Quick tip: Batch resize and convert images in Linux

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
Read more: Design, Productivity, Linux
Trackbacks & Pings
Comments
-
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.
-
try it like this
save the following into a simple script file and edit as desired, save, ensure it’s executable, and then runfor i in ls -C1 *.jpg
do
convert -verbose -resize 600×900 -comment “(c) Paul Sahlin Tiffany’s” $i optional_preffix_$i_optional_suffix
done -
you can also use
mogrify -resize 400×400 ./*.jpg
that’s what i had to do on mandriva 2007.1
-
And what would be the command to convert *.gif in a directory into .jpg files?
-
@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 -
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… -
Resize Multiple Images chek this link:
http://albertux.ayalasoft.com/2008/10/20/resize-multiple-images/

Batch Photo Conversion « 36 Chambers - The Legendary Journeys on 11 Mar 2007 at 12:25 pm
[…] This page has a few ways of handling the problem, and now that I have that done, I will be able to put up my posts more easily. Yay for productivity-enhancers! […]