Quick tip: Batch resize and convert images in Linux

Image magick icon
You can batch resize and convert images in Linux from the terminal using ImageMagick. The first step is to install ImageMagick. You can download the ImageMagick from the ImageMagick homepage or ImageMagick is widely available in the repositories and can be downloaded using apt-get install imagemagick.

There are a ton of commands available from the ImageMagick guide. I will walk you through the most commonly used commands: resize, convert, and quality (compression).

Enter the following command to resize all JPEG images in a directory to 750×500 pixels. Obviously, you can change the 750×500 to whatever dimensions you prefer:
convert -resize 750×500 *.jpg

Enter the following command to convert a JPEG into a GIF. You can convert any format image, it doesn’t have to just be JPEG to GIF:
convert image.jpg newImage.gif

Enter the following command to reduce the quality of every JPEG in a directory down to 80%. You can change the 80% to whatever percentage you prefer:
convert -quality 80% *.jpg

Please visit the ImageMagick homepage to learn about the thousands of other commands available.

Note: You can also combine commands.  For example:
convert -resize 750×500 -quality 80% *.jpg

Trackbacks & Pings

Comments

  1. sorry but this command:

    convert -resize 750×500 -quality 80% *.jpg

    only convert the last jpeg file, not all them.

    I’m on Kubuntu edgy.

  2. try it like this
    save the following into a simple script file and edit as desired, save, ensure it’s executable, and then run

    for i in ls -C1 *.jpg
    do
    convert -verbose -resize 600×900 -comment “(c) Paul Sahlin Tiffany’s” $i optional_preffix_$i_optional_suffix
    done

  3. you can also use

    mogrify -resize 400×400 ./*.jpg

    that’s what i had to do on mandriva 2007.1

  4. And what would be the command to convert *.gif in a directory into .jpg files?

  5. @Evert Meulie: That’s one of the very clever things about ImageMagick. You just use the extension of the file that you want it to be converted to. Example:

    $ convert img1.gif img1.jpg
    $ for img in *gif; do
    > base=`basename $img .gif`
    > convert “$img” “$base.jpg”
    > done

  6. I have no idea what “convert -quality 30% *.JPG” does on my machine right now. The only thing I know is that it’s consuming all my system’s ressources and doesn’t even touch my JPGs…
    It works quite well with 1 file, but the wildcard gets it to bug around…

  7. Resize Multiple Images chek this link:

    http://albertux.ayalasoft.com/2008/10/20/resize-multiple-images/

Post a Comment


Your email is never published nor shared. Required fields are marked *



© 2006-2007 Maxim Software Corp.  All rights reserved.