normally i'd just use imagemagick's convert, but I had a bunch of scanned images that i had to crop the content which was all over the place.

So i opened some 30 images on gimp, manually cropped them all. Now I found myself wanting to resize them to 66% of the size and export them all to their original name (they were open from PNG images)

and i realize there is no easy way to do that. or is there?

All searches tell me to use command line or scripts. but nothing that will work on already open images via the UI.

  • Close them all and then resize them from the command line. – DavidPostill Apr 20 '16 at 12:49

The Python console can actually allow you to do that in a couple lines of screen directly, without creating a script -

for img in gimp.image_list():
    img.scale(int(img.width * 0.66), int(img.height*0.66))
    tmp = pdb.gimp_image_duplicate(img)
    pdb.gimp_image_merge_visible_layers(tmp, CLIP_TO_IMAGE)
    pdb.gimp_file_save(tmp, tmp.layers[0], img.filename, img.filename)

What takes more line than it should is that GIMP really wants to "save" the image as is - so, one needs the steps of duplicating (internally), merging to a single layer, and deleting (just removing it from GIMP's memory, not from disk) - if all your images are a single layer already, that may be reduced to this 3 lines:

for img in gimp.image_list():
    img.scale(int(img.width * 0.66), int(img.height*0.66))
    pdb.gimp_file_save(img, img.layers[0], img.filename, img.filename)

To type these (or simply copy and paste directly from here into there), go to Filters->Python->Console and type or paste the snippets above to the >>> prompt.

WHile you are at it, if you want to automate any other operation, take your time to click the "browse" button on the Python console dialog, and check all available operations. Hitting the "apply" button will paste a template of the call to that function on your prompt (don't forget to prefix spaces to that pasted template,so that this call is aligned inside the for block - and to replace the template suggested variable names for actual parameters)

  • that is awesome! thank you. i completely missed the .image_list() while browsing the docs – gcb Apr 21 '16 at 17:51
  • 1
    Not quite sure it is properly documented - Python-GIMP extras that are not in the PDB are hard to find about without reading the source code.A tip is to look at the dir output for the GIMP module and other objects (i.e.: dir(gimp)) – jsbueno Apr 22 '16 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.