#!/usr/local/bin/perl use GD; print "Content-type: text/html\n\n"; my $maxheight = 100; my $maxwidth = 100; my $srcimage = GD::Image->newFromJpeg("churchmiddle.jpg"); 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, ">test.jpg") || die "Cannot open churchmiddle.jpg: $!\n"; print FILE $newimage->jpeg;