use strict;
use Image::Magick;
my $p = new Image::Magick;
$p->Read('c:/data/eps/cookie.jpg');
$p->Resize(geometry=>'100x80');
$p->Write('c:/data/eps/cookie_new.jpg');
This reduced a 40 Kbytes jpeg-image to a 4 Kbytes image.Update: I tried your command line and it does reduce the file size. Maybe we have different (versions of) ImageMagick programs running? I run "ImageMagick 6.3.4 06/14/07 Q16" on Windows XP Pro
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
| [reply] [d/l] |
Hi, Thanks for your reply. I have an 84kb image and just using Resize(width=>$x, height=>$y) reduced to around 62kb. using your geometry reduces further to 56kb. On further reading I have used $x = $image->Thumbnail (width=>160, height=>$r);
and this has got it down to 23kb! (But a partial reason for the reduction is I have reduced the resulting file dimension from width 180 to 160. Still it's a pleasing result!)
I am using rented server which doesn't have telnet so I need to write the command line stuff into an actual script to action it, and I don't know how to do that. I'd be interested to know if it further reduces file size.
| [reply] [d/l] [select] |
If you are desparate to get size down, you can add a quality option, it will start to make things grainy, if below .75.
$image->Write($outfile.jpg, compression => 'JPEG', quality=>.5);
# I think it goes 0 to 1 for quality, ImageMagick has minimal
# perl docs, so groups.google.com search for examples
| [reply] [d/l] |
| [reply] [d/l] [select] |
Here is a way to do batch mode reducing, efficiently.
( code adapted from an example by Merlyn that reuses the IM object )
#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;
my $image = Image::Magick->new;
umask 0022;
my @pics= <*.jpg>;
foreach my $pic (@pics){
my ($picbasename) = $pic =~ /^(.*).jpg$/;
my $ok;
$ok = $image->Read($pic) and warn ($ok);
my $thumb = $picbasename . '-t.jpg';
$image->Scale(geometry => '100x100');
$ok = $image->Write($thumb) and warn ($ok);
undef @$image; #needed if $image is created outside loop
print "$pic -> $thumb\n";
}
| [reply] [d/l] |