Rotate and resize images using Imagemagick | January 11, 2006-->
January 11, 2006Let's assume that you have a bunch of images for which you want to create thumbnails. The thumbnails should be rotated 90 degrees counter clockwise (that is 270 degrees clockwise), scaled to a specific size and renamed from abc_large.png to abc_thumb.png.
powerbook:~ sts$ cat convert.sh #!/bin/bash # create directory for thumbnails mkdir thumbs # the large images are in ./images for i in $(ls images/*.png) do # Rotate all images img=`basename $i` `convert -rotate 270 $i thumbs/$img` echo "rotate $img" # scale all images. replace suffix new_name=`echo $img | sed s/_large/_thumb/` `convert -scale 40x120 thumbs/$img thumbs/$new_name` echo "scale thumbs/$new_name" done
The following snippet crops all images in the current working directory to 222px x 185px. Furthermore the image type will be changed from gif to jpeg using the original image name. And all in one line of shell script.
Welcome to Darwin! macbook-sts:~ stefan$ cd ~/images/ macbook-sts:~ stefan$ for i in $(ls); do name=`echo $i | sed s/\.gif/\.jpg/g`;\ convert -crop 222x185+0x0 $i $name; doneThe
convert command is part of the Imagemagick software package.
See http://www.imagemagick.org/ for download and install instructions.
