Batch resize of images in Linux

I always resize images to smaller resolutions and add an overlay text before uploading to Flickr.

This is a script to do it using ImageMagick

To resize,

#!/bin/sh

mkdir upload
for f in *.jpg
do convert $f -resize 1024x1024 upload/$f
done

This will resize all images such that the longest side is 1024px in length, preserving the aspect ratio.

To resize and add an overlay text,

#!/bin/sh

mkdir upload
for f in *.jpg
do convert $f -resize 1024x1024 -pointsize 15 -fill white -gravity southeast -annotate +10+10 'Your overlay text' upload/$f
done

This will add an overlay text at the bottom right corner of the image, in white colour and 15pt size.

Save the script as resize.sh to the directory containing your images. Make it an executable and run it.

[tony@localhost pics]$ chmod +x resize.sh 
[tony@localhost pics]$ sh resize.sh 

You can use this same technique to add a copyright tag, watermark text or your logo to your images.

For full details on image resizing, text positioning refer,
http://www.imagemagick.org/script/command-line-processing.php#geometry
http://www.imagemagick.org/Usage/annotating/
http://www.imagemagick.org/Usage/fonts/

Leave a Reply

Your email address will not be published. Required fields are marked *


seven + = 13

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>