#! 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"; binmode (FILE); #-- ONLY FOR WINDOWS --# print FILE $newimage->jpeg;