Yay for python-fu!
Ever needed to batch-resize some pictures and convert just didn’t cut it? Imagemagick apparently tries to ‘optimize’ images, so this means that a 32bit bitmap file will always end up in 24bit format later.
Well, as it turns out The Gimp is very scriptable! By creating the following file and calling it ‘resize.py’ you can now make your dream come true! ;
SCALE = 0.5
DIR = "/path/to/images"
from gimpfu import *
import gimp
import os
for root, dirs, files in os.walk(DIR):
for file in [f for f in files if f.endswith(".bmp")]:
try:
fullname = os.path.join(root, file)
print “processing”, fullname
img = pdb.gimp_file_load(fullname, fullname)
pdb.gimp_image_scale(img, img.width*SCALE, img.height*SCALE)
layer = img.layers[0]
pdb.gimp_file_save(img, layer, fullname, fullname)
pdb.gimp_image_delete(img)
print fullname, “done”
except:
print fullname, “Failed!”
pdb.gimp_quit(True)
It’s not the prettiest code ever written, but it does the job. Run it like so:
gimp-console -i -n –batch-interpreter=’python-fu-eval’ -b - < resize.py
I hope this will be useful to someone else some time

Leave a comment
You must be logged in to post a comment.