[juneau-lug] Re: Resizing jpegs

  • From: Matt Heavner <matt.heavner@xxxxxxxxxxxxxx>
  • To: juneau-lug@xxxxxxxxxxxxx
  • Date: Wed, 28 Jul 2004 09:26:22 -0800

Hi James and everyone,

My digital camera takes jpegs but uses something close to 100% quality 
settings.  The first thing I do when starting to put them on the web is 
to change the images to 75% quality, and this drastically reduces the 
file size (typically from > 1MB to < 100 kB for 1920x1600).  A script 
that uses the perlmagick modules (with some other useful code commented 
out) is attached.  I'm sure that this is mostly borrowed from somewhere 
(maybe the perlmagick docs?), but I've forgotten where, so I can't give 
proper credit..

#!/usr/bin/perl -w

# Matt Heavner 2003/08/27
# go through a directory and save pictures w/ quality 75 setting
# It is written to look for *.JPG and save them as *.jpg
# The images can also be reduced by 50%, but that is commented out

use Image::Magick;
$ver = 0; #0 means don't be verbose...

@files = `ls *.JPG`;

foreach $file (@files) {
   chop $file;
   $file =~ /(\w+)\056JPG/;
   $stub = $1;
   if ($ver) { print "Stub is $stub\n";}

   $image = Image::Magick->new;
   $status = $image->Read($file);
   warn "$status" if "$status";

#  $status = $image->Resize(geometry=>"50%");
#  warn "$status" if "$status";

# Use the 216 web-safe color cube
#  $cube = Image::Magick->new;
#  $status = $cube->Read('NETSCAPE:');
#  warn "$status" if "$status";
#  $image->Map($cube);

   $status = $image->Write(filename=>"jpg:$stub.jpg",quality=>"75");
   warn "$status" if "$status";

   # Neatly dispose of our object
   undef $image;
}

-- 
| Matt Heavner, Assistant Professor of Physics
| University of Alaska Southeast
| 11120 Glacier Highway, Juneau, AK 99801
| Phone: (907) 465-6403
| If Heisenberg was uncertain, why are you so sure?

------------------------------------
This is the Juneau-LUG mailing list.
To unsubscribe, send an e-mail to juneau-lug-request@xxxxxxxxxxxxx with the 
word unsubscribe in the subject header.

Other related posts: