In this tutorial I will show you how to batch resize and compress images in ubuntu or in any other linux distros(debian,arch and fedora).

‘Convert’ command is a very powerful image manipulation utility which comes preinstalled in almost all linux distributions (ubuntu,debian,arch and fedora) and it is a part of ImageMagick software suite.

Check if convert command is available on your linux distro
 convert -version 


Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114
Copyright: © 1999-2017 ImageMagick Studio LLC

If above command is not found on your linux distro you can install it by typing below command.

Install convert tool on ubuntu / Debian
 sudo apt-get install imagemagick 
Install convert tool on fedora
 sudo dnf install imagemagick 


Install convert tool on arch
 sudo pacman -S imagemagick 

Note: It’s always good idea take backup of your images before  running convert command.

Batch resize and compress images with convert command

Below command will resize and compress all images ending with .jpg extension in a ‘for loop’ and save the compressed/resized image as ‘filename-Optimized.jpg’.

-quality :  this option is used to set the image compression level in percentage

-resize : this option is used to resize the image to a given resolution , You can use  -resize option with width ( -resize 1600x ) only or both width and height ( -resize 1600×900), In both cases convert command will automatically adjust the given resolution to get optimum aspect ratio  so you don’t have to worry about stretched images.

Note: some jpeg image extensions may end with .JPG (in capital letters) ,Since linux is case sensitive you may need to adjust the bash script accordingly.

open terminal and cd into the directory containing your photos and execute below command

 mkdir photos-Optimized;for photos in *.jpg;do convert -verbose $photos -quality 85% -resize 1600x900 ./photos-Optimized/$photos-Optimized.jpg ; done 

Voila ! Now you have successfully batch resized/compress images, You can see the optimized images in current directory with the file extension ‘filename-Optimized.jpg’.

How to batch resize and compress images in linux
Tagged on:         

2 thoughts on “How to batch resize and compress images in linux

  • September 27, 2017 at 4:24 PM

    Hi great command line !
    I wisch only to improve it a little bit, and for the sake of usability put all optimized jpg files in to new folder optimized. How it will look like a new command that way ?

    Great Thanks !

    • September 27, 2017 at 9:10 PM

      Hi Marcin,
      Good question , you can do something like this mkdir photos-Optimized;for photos in *.jpg;do convert -verbose $photos -quality 85% -resize 1600x900 ./photos-Optimized/$photos-Optimized.jpg ; done , I have also updated the post. Thank You!


Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: