(Comments)

To resize all images in a directory in bash first install ‘imagemagick’. In ubuntu this can be done in the terminal with the following command:

sudo apt-get install imagemagick

A target directory for the thumbnails will need to be created as the thumbnails will be output with the same name as the images.

In this example we will assume you are in the current directory with all the images to be resized, they are all .jpg files, we want the output to be 100px and a folder named ‘thumbs’ has been created within that folder. The command will be:

find . -name "*.jpg" | xargs -i convert -scale 100 {} ./thumbs/{}

To change the file type to be converted or limit for a partial name match change “*.jpg” to the relevant name and file type using wildcard characters as appropriate.

For example if we want to process all .png files with ‘bat’ in the name we would use the following:

find . -name "*bat*.png" | xargs -i convert -scale 100 {} ./thumbs/{}

Usually the scale is defined in either pixels or percentage. If pixels are required (as per above) no unit is provided. If a percentage of the original size is required add % after the percentage figure.

For example if we continue with the previous example and want to scale all the .png files to 23% we would use:

find . -name "*bat*.png" | xargs -i convert -scale 23% {} ./thumbs/{}

To change the directory just change the section ./thumbs/{}.

For example if we continue with the previous example and want to output to a folder named ‘output’ that is kept in the same folder as the parent folder to the images we would use:

find . -name "*bat*.png" | xargs -i convert -scale 23% {} ../output/{}

There are many other options available which can be researched.

ADDENDUM June 10th, 2012

This may also be useful….

find ./ -type f -name '*.jpg'| xargs -i mogrify -resize '800x600>' -quality 85 {} ./{}

In the resize the > token represents do not resize if less than that dimension.

Currently unrated

Comments