Rate this page del.icio.us  Digg slashdot StumbleUpon

Tips and tricks: How do I resize multiple image files using command-line tools?

by the editorial team

Image file size depends on the amount of image details it has. The higher the image quality, the better the resolution but the larger the resulting file size. Web galleries tend to load very slow and sometimes inaccessbile if photos have very high resolutions.

The mogrify command allows users to resize multiple image files at once. mogrify comes with the ImageMagick package. ImageMagick is a program used to resize, rotate, manipulate and display images. It can read, convert and write images in JPEG, TIFF, PNM, GIF and other Photo CD image formats.

Check if the ImageMagick package is installed:

rpm -q ImageMagick

To install the ImageMagick package on Red Hat Enterprise Linux 3 or 4, use the up2date command:

up2date ImageMagick

On Red Hat Enterprise Linux 5, use the yum command:

yum install ImageMagick

After installing ImageMagick package, use mogrify to resize multiple image files. See example command below in resizing all JPG photos in the current working directory to 640 pixels in width while maintaining its original aspect ratio:

mogrify -resize 640 *.jpg

To resize the resolution of all JPG image files to exactly 640 pixels in width and 480 pixels in height, use:

mogrify -resize 640x480! *.jpg

3 responses to “Tips and tricks: How do I resize multiple image files using command-line tools?”

  1. Danilo Câmara says:

    Notice that the above commands will overwrite the images. To keep the original images and resize to another directory use the option -path:

    mogrify -resize 640 -path outputdir *.jpg

  2. uosiu says:

    mkdir small
    for a in *.jpg; do
    convert -thumbnail 800 $a small/$a;
    done

  3. Booboo says:

    I have copied a bunch of files in a separate directory of my choice.
    Therefore i don’t care about them that much as long as i have the originals!
    So … the mogrify -resize 600×800! *.jpg did the job for me quite nicely

    Thank you very much !
    I’m happy :-)

Leave a reply