01-18-2024, 10:11 PM
Hello,
I just started today with this quest:
1.) Read the filename and save it.
2.) Resize the image to a specific aspect ratio.
3.) Add a prefix to the filename and save it as an jpeg in a specific folder.
4.) Undo all steps and repeat steps 2. und 3. different values.
I came this far:
But I have some questions to fill the blanks:
Q1: I know now that image.name does not work properly. Is there another way besides using pdb.gimp_image_get_filename(image) and trim the complete path down to the filename to just get the name of the file I imported?
Q2: What type is "drawable" - I could not find a good explanation. Do I use this correctly?
Q3: Undo is still a miracle for me. I saw that you can create groups and that you can enable, freeze, and disable it but I dont know how to trigger a simple undo to reverse steps 2. and 3. to the back to the original image.
Thanks in advance!
I just started today with this quest:
1.) Read the filename and save it.
2.) Resize the image to a specific aspect ratio.
3.) Add a prefix to the filename and save it as an jpeg in a specific folder.
4.) Undo all steps and repeat steps 2. und 3. different values.
I came this far:
Code:
from gimpfu import *
# The real code.
def setAspectRatios():
# create the object of the image
image=gimp.image_list()[0]
# resizes the file to AR 2-3
pdb.gimp_image_resize(image, 5333, 8000, -345, 0)
# create the new name AR 2-3
img_name_ar_2_3 = "AR_2-3_" + image.name
# define drawable
drw = image.layers[0]
# save the image as jpeg
pdb.file_jpeg_save(image, drw, img_name_ar_2_3, img_name_ar_2_3, 0.90, 0, 1, 1, "Aspect Ratio 2-3", 3, 1, 0, 2)
register(
'set-aspect-ratios', # Unique ID,
'create different aspect ratios', # Description/title
'Add a white layer', # Help
"Author", # KJ
"Author", # Copyright KJ
"2024", # Copyright 2024
'Set Aspect Ratios', # The menu label
"RGB*", # The type of images it can work on. Use "*" for all types
# [ # List of input parameters
# (PF_IMAGE, "image", "Input image", None)
#
#],
[], # List of output parameters
setAspectRatios, # The Python code that implementsthe plugin
menu="<Image>/Layer", # Where the menu label above appears
)
main()
But I have some questions to fill the blanks:
Q1: I know now that image.name does not work properly. Is there another way besides using pdb.gimp_image_get_filename(image) and trim the complete path down to the filename to just get the name of the file I imported?
Q2: What type is "drawable" - I could not find a good explanation. Do I use this correctly?
Q3: Undo is still a miracle for me. I saw that you can create groups and that you can enable, freeze, and disable it but I dont know how to trigger a simple undo to reverse steps 2. and 3. to the back to the original image.
Thanks in advance!