Resizing images with convert

Downsize JPGs by 50%

convert -resize 50% *.jpg

convert has loads of other options, for e.g changing dimensions or quality.

NOTE 1: It has a problem with patch resizing, whereby it freezes the computer. I’ve found batches of 100 is too much. Batches of 10 is ok.

NOTE 2: It also seems incapable of keeping the original image names. You can use bash command line or script. See below.

Command line

To reduce a whole load of images in a directory do:

for i in *.jpg; do convert "$i" -resize 50% "${i%%.jpg*}_new.jpg"; done

or for subdirectory recursion and filenames with spaces do:

find . -type f -name "*.jpg" | while read i; do convert "$i" -resize 50% "${i%%.jpg*}_new.jpg"; done

(source http://forums.fedoraforum.org/showthread.php?t=242084)

Script

#!/bin/bash
#
# Resize all images with the given extension to the given size.
#
# This script is to overcome limitations with convert that sees it crash when dealing
# with too many images and also work around its inability to preserve filenames.

if [ $# -eq 2 ]; then
  for i in *.$1
  do
    convert $i -resize $2 $i
  done
else
  echo "Usage: ./resize_images.sh [extension] [size]"
  echo "Example: ./resize_images.sh jpg 90%"
fi

Change format

convert image.tif image.jpg

Last modified: 19/05/2011 Tags:

Related Pages

Other pages possibly of interest:

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top