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/
-
I fancy this command, which i have “invented” for several purposes
ls *.jpg | tr ‘\n’ ‘00′ | xargs -0 -i{} convert -resize 800×600 “{}” “resampled/{}”
-
When i ran the command:
convert -resize 576×576 *.jpg
it took a while to convert all the *.jpg files
but they are renamed as
lastFileName-0.jpg
lastFileName-1.jpg
lastFileName-3.jpg …and so on. -
if you want to restrain only by height (as i wanted) this works
mogrify -resize ×100 *.jpg
-
I just love how Wordpress decides it must mangle text to be pretty typographically. All of the “x”s (in 400×400, etc.)(as well as all the single and double quotes) in this article and comments are “broken”, and have to be replaced with their plain ASCII versions.
-
Hi,
I need a help to run this batch file using php exec in linux environment.Thanks,
Vijay -
keep it easy
for multiple file conversion that works
mogrify -resize 25% *.jpg
simple
-
This is brilliant! Now I can resize all my photos like a pro Linux user.
This page is soo bookmarked!
-
Great page, thank you
It’s much better to do a loop than let convert deal with the wild cards on the command line
for ff in *.jpg
do
convert -verbose -resize 50% -quality 75% $ff X_$ff
doneJust saved my day.
Remember always work over with copies of the images
-
The script written by Abschnitt5 works fine. Thanks.
-
WARNING:
for does not work with files that have spaces in their names, in such case use:
find -type f -name “*.jpg” -exec convert ‘-verbise -resize 50% -quality 75%’ ‘{}’ X_’{}’ \;
see man find
-
Hi, I am having problems with the following command, run in a bash shell (ubuntu 12.1 desktop):
for i in ls -C1 *.jpg
do
convert -resize 480×270>
doneerror: convert.im6: option requires an argument `-resize’ @ error/convert.c/ConvertImageCommand/2380.
No matter if I quote the resize parameters, escaped or non, i recieve the same error. Any help is appreciated.
-
sorry i fixed that myself. stupid, was missing my bash variables.

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! […]
Abschnitt5 on 04 Jan 2011 at 2:01 pm
Imagemagik - Batchkonvertierung von Bildern…
Geht in der Konsole in das gewünschte Verzeichnis.
vim mybatchconvert.sh
#!/bin/sh
mkdir resized
for f in *.jpg
do convert $f -verbose -resize 25% -quality 90% -comment “proud made with linux” resized/$f
#do convert $f -verbose -resize 6% …