I need to change the background color of thousands of images. I know how to do it in GIMP one by one. But Any idea of how to do it automatically for thousands, maybe using a script?
Thanks!
I need to change the background color of thousands of images. I know how to do it in GIMP one by one. But Any idea of how to do it automatically for thousands, maybe using a script?
Thanks!
You can "pilot" GIMP through the script-fu or python-fu consoles, in a programatic way, tahta ffects the program interactively.
From whatver tests you make tehre, you can compose a script in either of those lnaguages (script-fu is actually Scheme). I'd suggest using Python for its higher level dealing with files and strings.
For example, to have GIMP open all image files in a directory (this is an example, not suitable for image processing):
Open filters->python->console
at the >>>
prompt type:
from glob import glob
for name in glob("/my/directory/*jpg"):
img = pdb.gimp_file_load(name, name)
pdb.gimp_display_new(img)
(the identation of spaces after the for
line is important because its Python's
way of delimitng code blocks - you don't need 4 spaces when tying interactively though,
just the same ammoutn of identation for each line)
This will open all jpg files in agiven directory. When you know what to do, instead of calling pdb.gimp_display_new, you call the functions to perform your action on the image, using the "img" object as the Image to act upon. The GIMP PDB API is visible clicking on the "browsw" button in the Python console window itself.
When you are done with your operations, call pdb.gimp_file_save
to export your image back to a fpg or png file (NB, you'd rather use another filename than the one you used to open the image, or they will be overwritten), and pdb.gimp_image_delete
to free up the memory used by that image (this only deletes the memory object, the image openned or just exported on disk are not touched, of course).
In time, you will certainly need to try calling the API functions in the interactive mode before running through a batch of images. To retrieve Image references to the existing open images in GIMP, call gimp.image_list()
(that will return a Python list with all open images - to get the first image in the list in a variable, do: img = gimp.image_list()[0]
)
To create a gimp-python plug-in with whatever you develop, check the documentation at http://www.gimp.org/docs/python/