silent11 has asked for the wisdom of the Perl Monks concerning the following question:
#! perl -w use GD; my $source = 'meat.jpg'; my $Thumbnail = 'thumb_' . "$source"; my $maxheight = 150; my $maxwidth = 150; my $srcimage = GD::Image->newFromJpeg("$source"); my ($srcW,$srcH) = $srcimage->getBounds(); my $wdiff = $srcW - $maxwidth; my $hdiff = $srcH - $maxheight; my $newH; my $newW; if ($wdiff > $hdiff) { $newW = $maxwidth; $aspect = ($newW/$srcW); $newH = int($srcH * $aspect); } else { $newH = $maxheight; $aspect = ($newH/$srcH); $newW = int($srcW * $aspect); } print "converting $srcW:$srcH to $newW:$newH\n"; my $newimage = new GD::Image($newW,$newH); $newimage->copyResized($srcimage,0,0,0,0,$newW,$newH,$srcW,$srcH); open(FILE, ">$Thumbnail") || die "Cannot open $Thumbnail : $!\n"; print FILE $newimage->jpeg;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(Guildenstern) Not using GD, but it works...
by Guildenstern (Deacon) on Apr 17, 2002 at 21:03 UTC | |
|
Re: GD thumbnail script errors
by fireartist (Chaplain) on Apr 17, 2002 at 23:05 UTC | |
|
Re: GD thumbnail script errors
by blogan (Monk) on Apr 17, 2002 at 22:22 UTC | |
|
Re: GD thumbnail script errors
by silent11 (Vicar) on Apr 17, 2002 at 21:23 UTC | |
|
Re: GD thumbnail script errors
by mattr (Curate) on Apr 18, 2002 at 14:00 UTC | |
|
Re: GD thumbnail script errors
by dmmiller2k (Chaplain) on Apr 20, 2002 at 12:07 UTC |