Garten Eden

#linux #programming #android #online #stuff

Batch Processing with ImageMagick

Being a famous image converter software on both the web and desktop, ImageMagick is a must-have tool. It reads, writes and edits pretty much most of the image formats in use, so compatibility is nothing you have to worry about. Lets see how easy the syntax of the converter convert out of this magic package is.

convert before.jpg -resize 50% after.png

The image before.jpg got shrinked to 50% of its pixel and saved to after.png. That’s it. This easy way you can scale, crop, sharpen, blur, correct colors and transparency, change bit-depths, add effects and much more.

Batch Processing

If you want to edit many pictures all at once, you can use this BASH-one-liner in your console. Applying it to our example, we get converted all JPEG-files in the current directory:

for i in *.jpg; do convert $i -resize 50% $i.png; done

Example: Creating Thumbnails for the Web

This way you create thumbnails for the web fast as lightning. By installing pngcrush you make sure that the created PNG-files are stored and compressed as well as possible.

for i in *.jpg; do convert $i -resize 160x120 $i.png; done
for i in *.jpg; pngcrush -brute -rem gAMA -rem cHRM -rem iCCP -rem sRGB -rem gAMA -rem alla -rem text $i $i.crushed; rm $i; mv $i.crushed $i; done

The settings for pngcrush cause maximum compression while the swith -brute tries all possible options to find the best one. The other options remove all comments, profiles and useless stuff (in most cases).

Then, if you feel not satisfied with the naming scheme of the files, pyRenamer is the answer. It is self-explanatory and very handy.

Ubuntu Installtion

sudo apt-get install imagemagick pngcrush pyrenamer


Your comment:

So far... comments


Wait a sec, loading...

Email (not published)

Homepage (optional)

Comment... (code tag allowed)