How to resize a batch of images on Linux?

Posted on In QA

Resizing images on Linux with gThumb is easy. However, I have a batch of images inside a folder. Manually resizing them will consume too much time.

How to automatically resize them on Linux with a script?

You can use convert from ImageMagick together with bash script to resize images inside a directory.

mkdir resize; 
IFS=$(echo -en "nb"); 
for i in *; do 
    echo $i; convert $i -resize 600^ resize/$i; 
done

The script will make a new directory named “resize” in current directory, resize all images in current directory to smaller ones of width 600px, and store the resized images into “reisze”.

The line IFS=$(echo -en "nb") is a bash trick to handle situations where images file names have spaces.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

One comment

Leave a Reply

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