Monthly Archives: May 2010

Resizing images in Ubuntu (in Bulk!)

A common problem relating to sharing photos is that the files to are TOO BIG! When I load up my 7-megapixel camera, photos are close to 5mb each! I want to put them on the net or email them to people, but the size limits me. Here I’ll show you how I run these through a single command to reduce them to whatever size I need, using ImageMagick and a perl script I wrote. This really is pretty easy and hopefully these instructions are useful even for linux newbs. Incidentally, this will also work on a mac if you have Imagemagick and Perl installed, or an Windows machine under Cygwin.

First you’ll have to install Imagemagick. This should be as easy as a sudo apt-get install imagemagick. Of course you need perl, but that’s standard on any linux install. Now here’s the perl script:

use Cwd;
$some_dir = cwd;
print $some_dir."n";
opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
system("mkdir small");

while ($_ = readdir(DIR)) {
next if($_ =~ /^./ || -d "$some_dir/$_" || /.pl/);
print ":convert -resize 800 -quality 80 $_ small/$_"."n";
system("convert -resize 800 -quality 80 $_ small/tn_$_");
closedir DIR;


1. Save the above script as (copy and paste it into a new text document).

2. Adjust the image width (800 in the example) and quality (80 in the example), and put the script in a folder.

3. Put all the images you want to resize into the same folder.

4. Open a terminal, cd to the folder, and type


That’s it! This will make a subfolder called small and put the newly resized images in there.

If you’re not happy with the file size, just do it again, it will overwrite anything. I find this little script really useful — you can now email however many pictures you want. You can also use this script to make thumbnails for a web site: just set the size to 200 or 300, lower the quality a bit, and you can get images that are around 30K each.