Monday, March 19, 2007

Batch jpeg image resize in linux

The (jpeg) photos we take using digital camera are just too large so to save space and bandwidth, it's better to resize them before uploading them to online photo sharing sites like Picasa or Flickr. Here's how i do it in linux..

Basically two commands are used here.
1. djpeg - decompress a JPEG file to an image file
2. cjpeg - compress an image file to a JPEG file

So to resize, i run this script on a folder containing the image files.


mkdir resized
for i in *.JPG
echo 'Resizing image..' $i
djpeg -scale 1/2 $i | cjpeg > resized/$i

After script is done, a folder named 'resized' is created containing the resized images..

Both the program djpeg/cjpeg isn't installed by default, they're part of libjpeg-progs package. Under Ubuntu you can get it by

sudo apt-get install libjpeg-progs

(thanx subir dai for pointing this out)


  1. thanks for the info. was helpful for me.
    keep it up with more tips and tricks

  2. Okay nice blog you have got.
    I suggest you to change the template. Find one to which you can add second side bar. I hope you can edit the css to do that. (I cannot do! :P)

    all the best

  3. Hey jwalanta, that was really helpful! But it would've been better if u'd mentioned about the package that installs cjpeg and djpeg. They are part of the package 'libjpeg-progs' :) for others information.

  4. i cannot but do like you said... sorry...

    Mr Editor