I’m working on a project that requires me to change several hundred images(somewhere around 550). They’re all the same size and type. Each image needs several color corrections. Initially I use color exchange for the top 50px, then I apply a hue of 360 to the bottom portion, then color exchange several shades of the resulting color to white. There are several individual files that I need to change even more at that point, but much less than the overall bulk. It’s a ton of work having to open each individual image and go through the motions. Is there any way to apply the same techniques to multiple images at once ? It would vastly lower my workload.
This is my first post here so if this is incorrect syntax for questions please let me know and I’ll edit this post to match any format necessary. I’ve tried googling and I can’t find an answer. Thanks!
As put in the comment, this is a workload that will require scripting GIMP –
although it can be done in a more or less interactive way (as individual images need separate treatment, that may actually be needed).
If you check
Filters->Python->Console you will get an interactive Python console, from which you can interact with GIMP – and if you want a solution that will add new functions (perhaps just composing some existing operations) to the menus, you will have to write a plug-in.
Writing Python plug-ins can be easier than it sounds – you use the interactive mode to figure out the GIMP calls you will need for your image, and wrap those with 4 lines of boiler plate code you can copy, paste and adapt from any existing plug-ins
The docs for plug-ins are here: http://www.gimp.org/docs/python/
And even over stackoverflow yoiu can find minimalist examples of plug-ins that just work – https://stackoverflow.com/questions/16020158/gimp-python-plugin
The key to get this to become productive for you (and at >500 images I believe it will certainly be worth your time) if to get minimally famiarized with the basics of Python – if you don’t know nothing about coding – you can follow the tutorial from https://docs.python.org/2/tutorial/index.html (it will work straight from the GIMP Python console) – until you grasp “variables”, “for loops” and “functions” – no need to go much further. And the second key is to press the “browse” button on the lower part of GIMP console dialog – that will allow you to search among the hundreds of available calls to fiddle with images open in GIMP. (Just hit the “apply” button to have it type-in the function call on the console for you) .
Some of these calls are simple to make – others will require a bit trial and error on your part so that you get it going.
To get access to an open (the rightmost) GIMP image from the Python console, type:
img = gimp.image_list()
From there on, the name “img” is a reference to the image, and can be passed to calls – for example, to brithgten up the topmost layer, you can type (or click on browse, search for “bright”, choose the apropriate function, click “apply” and edit the line until it reads:)
pdb.gimp_drawable_brightness_contrast(img.layers, 0.2, 0)
img.layers is a Python sequence containing all top-level layers. the  indexing picks the topmost layer,  will take the second, and so on.)
Now, let’s suppose you want to brighten up 550 (or thousands of) “.png” images lying on the same directory, and save them on a second directory – you leverage on the Python language power to deal with file names and strings, and these GIMP PDB calls:
Just type the lines bellow, following the indentation, and hit enter twice at the end (for Python to know you want to exit the for loop):
(the # indicate comments, no need to type what follows them)
import glob source_folder = "c:/mysource_image_folder/" #type your folder inside the quotes - append the final "/" dest_folder = "c:/destination_folder/" for filename in glob.glob(source_folder + "/*.png"): img = pdb.gimp_file_load(source_folder + filename, source_folder + filename) pdb.gimp_drawable_brightness_contrast(img.layers, 0.2, 0) pdb.gimp_file_save(img, img.layers, dest_folder + filename, dest_folder + filename) pdb.gimp_image_delete(img) # drops the image from gimp memory
And that is it. To automate more steps, justa dd the apropriate calls before the “save” call. To display the open image, call
d = pdb.gimp_display_new(img) (and pair it witha a call to
pdb.gimp_display_delete(d) call before
Since you want to perform automated tasks, interact with the image, them save and proceed to the next one – due to a technical problem in GIMP’s console (the “input” python function does not work – to pause until you press enter), I suggest the following hack – still working on the example above:
import glob.glob source_folder = "c:/mysource_image_folder/" #type your folder inside the quotes - append the final "/" dest_folder = "c:/destination_folder/" def auto(source_folder, dest_folder): for filename in glob(source_folder + "/*.png"): img = pdb.gimp_file_load(source_folder + filename, source_folder + filename) # palce calls to draw on the image before your interation here disp = pdb.gimp_display_new(img) yield img pdb.gimp_image_merge_visible_layers(img, CLIP_TO_IMAGE) pdb.gimp_file_save(img, img.layers, dest_folder + filename, dest_folder + filename) pdb.gimp_display_delete(disp) pdb.gimp_image_delete(img) # drops the image from gimp memory seq = auto(source_folder, dest_folder) next(seq)
(and each time you type
<enter>) gimp will save the currently open image, dispose of it, open and pre-process the next one and pause at the point you have to manually fiddle with it) (note that up arrow brings the
next(seq) text back)
Note that you can simply copy the snippet above, paste in an editor suitable for programming (lacking one, Windows’ notepad will do for it) – adjust your parameters (directory and file names), and paste the script directly on GIMP’s Python console)
update I followed this answer on S.O. writting a full-fledged plug-in with the example I started here: https://stackoverflow.com/questions/30302494/can-i-create-a-script-for-gimp-to-carry-out-a-number-of-processes/30398245#30398245