Tip : Batch resize images on Ubuntu Linux

After needing to optimize a lot of images at once, this weekend I needed to resize a lot of images to the same size because they were too big.

Like every other thing in Linux, there is a really simple tool to automate that. I used imagemagick to do that. Of course, there is certainly a lot of other things to make that work, but this is the first I've found and it works well.

So first, you need to install it if you don't have the tool :

sudo apt-get install imagemagick

And then, you can resize all the JPG images to a width of 640px of the current folder using the single command :

mogrify -resize 640 *.jpg

If you want the height, just add a x :

mogrify -resize x640 *.jpg

You can also specify maximum width and height, that can be useful if you have big images and you don't want a width larger than x and a height larger than y but you don't want to resize little images in the same folder. Here is an example resizing images if the width is larger than 1280 or height larger than 1024 :

mogrify -resize '1280x1024>' *.jpg

With all that commands, the ratio is preserved. If you want more informations on the possible resize options, you can consult the documentation of ImageMagick.

Hope that will help someone.

Related articles

  • Tip : Optimize images on Ubuntu Linux
  • Tip : How to switch from KUbuntu to Ubuntu
  • How to install a specific version of GCC on Ubuntu 11.04 (natty)
  • Ubuntu Lucid Lynx (10.04) is here !
  • Ubuntu Lucid Lynx Tip : Put the window buttons to the right
  • Install the Insight Debugger on Linux Mint (works for Ubuntu too)
  • Comments

    Comments powered by Disqus