Resizing or rotating a banch of images

It is very often that one has a need to rotate a bunch of images by 90 or 180 degrees clockwise or otherwise, or resize the same bunch of images to a certain size. Read more to learn how you can do it.

First of all, you should defenetely install ImageMagick. If you are using any of the modern Linux distributions (like Red Hat Linux 6/7/8/9), most probably you either have it already installed, or it is available on the distribution CD-ROM. If it is not, then you can always download it from http://www.imagemagick.org/.

Now for the fun part:



[leonid@home tmp]$ cd /home/leonid/files/images

[leonid@home images]$ for IMAGE in *.jpg ; do echo Working with $IMAGE ; mv

"$IMAGE" "$IMAGE.huge" ; convert -resize 800x600 "$IMAGE.huge" "$IMAGE" ; done

[leonid@home images]$ rm -f *.huge

Almost the same thing is for rotating. This time, let’s see how it will look in the script file:



#!/bin/bash

# go into directory with images

cd /home/leonid/files/images

# Repeat steps for each JPEG image in the directory

for IMAGE in *.jpg

do

# Do some noise so that we know that it's working

echo Working with $IMAGE

# Move original image to another file

mv "$IMAGE" "$IMAGE.huge"

# Rotate the backup file and save as original file

convert -rotate 90 "$IMAGE.huge" "$IMAGE"

done

# Remove backup copies

rm -f *.huge

That’s all folks. ImageMagick has a number of other utilities which can do a number of other things. Check them out.

2 thoughts on “Resizing or rotating a banch of images”

Leave a Comment