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)'


EDIT



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

#!/usr/bin/env bash

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


References


[1] http://www.lemur.com/dmm/culch/scriptsfu/index.html
[2] http://www.gimp.org/tutorials/Basic_Batch/

23 comments:

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

Steve

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:
\includegraphics[scale=0.5]{image.png}

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 macphun.com 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. http://www.manuscriptwriting.net/writing-manuscripts-with-us/ 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 https://www.professionalletterwriting.net/professional-letter-writing-services/ 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

shreekavi said...

Great post. keep sharing such a worthy information
IELTS Coaching centre in Chennai
IELTS Coaching centre in coimbatore
IELTS Coaching in madurai
IELTS Coaching in Bangalore
IELTS Classes in Bangalore
ielts coaching centre in bangalore
ielts Coaching centre in marathahalli
IELTS Coaching in Hyderabad
ielts training in bangalore
Ethical hacking course in bangalore
Software Testing Course in Bangalore

chandhran said...

The explanation given is really comprehensive and informative. Keep posting..
Data Science Course in Chennai
Data Science Courses in Bangalore
Data Science Training in BTM
Data Science Training in Marathahalli
Data Science Course in Marathahalli
Best Data Science Training in Marathahalli
Data Science Institute in Marathahalli
PHP Training in Bangalore
DOT NET Training in Bangalore
Spoken English Classes in Bangalore

Arjundevan said...

valuable blog,Informative content...thanks for sharing, Waiting for the next update...
SAS Training in Chennai
SAS Institute in Chennai
SAS Training Chennai
SAS Training in Velachery
SAS Training in Tambaram
clinical sas training in chennai
Mobile Testing Training in Chennai
QTP Training in Chennai
Hibernate Training in Chennai
DOT NET Training in Chennai

Riya Raj said...

Wonderful Post!!! Thanks for sharing this great blog with us.
Android Training in Chennai
app development course in chennai
Android Training Institute in Chennai
Android training
Android Training in Velachery
Android training in Adyar
Python Training in Chennai
Software testing training in chennai
JAVA Training in Chennai

Janu said...

The strategy you have posted on this technology helped me to get into the next level and had lot of information in it. The angular js programming language is very popular which are most widely used.


Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery








Aishu said...

Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us.
IELTS Coaching in chennai

German Classes in Chennai

GRE Coaching Classes in Chennai

TOEFL Coaching in Chennai

spoken english classes in chennai | Communication training