in reply to Resizing images without Image::Magick

This works for me just fine using GD.
#! 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;


-Silent11

Replies are listed 'Best First'.
Re: Re: Resizing images without Image::Magick
by Dr. Mu (Hermit) on Aug 25, 2002 at 00:27 UTC
    GD is a nice, easy-to-use tool, without the bulk of Image::Magick. But the catch, of course, is that it only works with paletted images.
        do some limit checking on that cgi =)
        http://www.xtype.org/albums/photo.cgi?img=01368&size=999999999999999x9999999999999999
        


        -Waswas