Saturday, 25 April 2009

Batch Image Editing using Script-Fu & GIMP

I have a large number of bitmap images which i need to include in a latex document. I didn't want to manually scale the images and save them to PNG format so I looked for ways of automating GIPM. Script-Fu is the language/interface for GIMP. It is unlike any other language I have used before and so it took me a little time to work out what was going on.

The script below, when saved to ~/.gimp-2.6/scripts/ directory can be used to convert any image file to a PNG and scaling it in the process to 150px by 150px.

(define (chris infile outfile)
(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE infile infile)))
(drawable (car (gimp-image-get-active-layer image))))
(gimp-image-scale image 150 150)
(file-png-save-defaults 0 image drawable outfile outfile)

To run it from the terminal:

gimp -i -b '(chris "infile.bmp" "outfile.png")' -b '(gimp-quit 0)'


Or to run this automatically on all bitmap files within a directory use this bash script:

#!/usr/bin/env bash

for myfile in *.bmp
echo Converting $myfile...
gimp -i -b "(chris \"$myfile\" \"$myfile.png\")" -b "(gimp-quit 0)"




Anonymous said...

Some impressive Lisp skillz there. Any reason you went for Gimp over Imagemagick?

Something like:
for x in *.bmp; do convert $x -resize 150 `basename $x`.png; done


Chris said...

Hmm, yeah, I was so used to using GIMP for this sort of stuff that, regrettably, I didn't look as far as Imagemagick. At least i learned a little Lisp though - although i'll try to avoid ever having to use it again :O its horrible.

Smiler said...

Those who can program LISP well praise it for being one of the most elegant programming languages around. Can't say that's my opinion though. I'd always wanted to try it: functional programming FTW!

Anyway: isn't 150x150px a bit small for a LaTeX image? If you're going to print that at 300DPI (which most laser printers do), then the image will only be 0.5x0.5 inches. What you ought to do is increase the 'resolution' of the PNG (tricky to do, but it's in the file somewhere) to 300DPI. Alternatively, graphicx can handle this: just include scaling dimensions when you include the image:

If you don't do this, then you'll get a pixelated image (unless that's what you wanted, of course).

Chris said...

you still can't use bitmaps in latex documents, so i have to convert them to pngs. Also the report is already at 80 pages and takes an age to compile each time. By scaling the images using gimp/imagemagick it speeds things up a little bit.

batch image converter said...

Batch editing means collective editing of a collection. If you want to edit a batch of photographs all together then it’s a good option to use a batch editing software for this purpose.

Unknown said...

This prompts me to save the destination file, can it be done automatically ?

Ben said...

Script Fu and GIMP is great image editing software I've been using since a long while and truly very much pleased with these. So thanks dude :)

Unknown said...

Impressive, Photo editting is my hobby, I often make stock photos using the Apps from AppStore. Want to share with you one great website where you can get photo editing software for mac sure you find there something useful for you. Good luck.

Tripti Oberoi said...

I regard all that you have Picsart Photo editing Playlist joined the degree that anyone is the concerned base.Admiring the time and exertion you put into your blog and point by point data you offer.

David Miller said...

Wow, great post.

David Miller said...

Chris, this post about Image Editing using Script. It is a really great post. You also gave two References list. Please click to explore about Service for Writing a Play Script. Thanks for this post.

RobertKY said...

This is what i was looking for days. The best post ever and also will help me a lot. The editing project is the key of all projects so we should go to site and learn what is good for me.

Jared Freeman said...

Batch Image Editing using Script-Fu & GIMP ! Is best title for my next assignment.If you guys are looking for some amazing titles and content then check it here.Thank you.

Unknown said...

When you are doing the academic subject and really want to write something on it then you should be more careful in every steps. for more help on your writing.

Unknown said...

There has so many way you can edit your image but using this script could have been so effective and so easy way to end. look here to find out more helpful tips on writing.

teeaa said...

To create a new language for the programming is creating a new universe for the generations to come because every Has its own limitations and benefits for the students so it is now up to you that how you handle such things.

Aparna said...

I really enjoy to read your marvelous blog and Here are some more useful tips. It was a really informative and very creative blog. I loved this article and kindly updating more post...

Tableau Training in Chennai
Tableau Certification in Chennai
Pega Training in Chennai
Primavera Training in Chennai
Unix Training in Chennai
Power BI Training in Chennai
Job Openings in Chennai
Excel Training in Chennai
Tableau Training in Thiruvanmiyur
Tableau Training in Porur