Resize multiple images using Linux

Resize an image is a simple operation: there are many software able to do that. The most obvious are Gimp or Photoshop. But what’s the right procedure to resize lots of images?

Imagine you have to prepare thumbnails for a gallery or resize all images to insert into a presentation or, again, reduce photos to send them by email, etc.

Open each image with Gimp or Photoshop and resize them one by one is foolish. How can we perform this operation in a simple way and without stress?

The solution

Use Linux command line. Resize multiple images with Linux is very simple by using ImageMagick suite.

First of all, let’s install ImageMagick that includes lots of tools to manipulate images. To do that, execute following command in terminal window:

$ sudo apt-get install imagemagick

Now, lots of new commands are available (check ImageMagick command line tools for more details). We will use mogrify that is designed to

[…] resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.

Of course, it can work on one or more images at time. We simply can specify filename to act on a single image, or use command line wildcards to act on multiple files.

So, let’s see some examples of morgify usage. For more detailed informations and complete list of options, please check ImageMagick Mogrify manual page.

Resize an image to 75% of its original size:

$ mogrify -resize 75% image.jpg

Resize all JPG files in the folder 75% of their original sizes:

$ mogrify -resize 75% *.jpg

Resize all images in the folder to 640×480 pixels:

$ mogrify -resize '640x480' *

Resize all images to width of 640 pixel mantaining aspect ratio:

$ mogrify -resize width='640' *

Resize all images to height of 480 mantaining aspect ratio:

$ mogrify -resize width='x480' *


Articoli correlati

  • Jon Anderson

    I actually find that Phatch is a really nice tool for this kind of problem. It’s graphical, so you won’t feel like a super hacker guy, but it’s nice to be able to see all the actions you’re going to make on your photos.
    My specific problem was that I wanted to upload all my photos to Google Photos with a maximum larger side size of 2048. The reason it was much easier with Phatch than with ImageMagick is that Phatch can work recursively without fancy ‘find -exec’ calls.

    • Valerio Galano

      Thanks Jon, I’ll try it.

  • Excellent tutorial and just exactly what I had been looking for. Thanks a lot! BTW i’ve another way to do this. I’m used to simple image reducer to convert and reduce image size on my Ubuntu.

  • mogrify -resize 640x480' *

    correct: mogrify -resize '640x480' *

    • daredevel

      Thanks you