brianviehland has asked for the wisdom of the Perl Monks concerning the following question:
use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use GD; $maxThumbSize = "150"; $name = param('filename'); $imagePath = "/home/user/public_html/images/" . $name; if ($name =~ m/gif$/) { &error('GIF files are copyrighted through 2004 +'); } if (($name =~ m/jpg$/i) || ($file =~ m/jpeg$/i)) { $sourceImage = GD::Image->newFromJpeg($imagePath); $retype = "no"; } elsif ($name =~ m/png$/i) { open (PNG,imagePath) || &error('Cannot Open PNG File'); $sourceImage = newFromPng GD::Image(PNG) || &error('Cannot Read Fr +om PNG File'); close PNG; $retype = "yes"; } ($fileWidth,$fileHeight) = $sourceImage->getBounds(); if ((($fileWidth > $maxThumbSize) || ($fileHeight > $maxThumbSize)) || + ($retype eq "yes")) { if ($fileWidth > $fileHeight) { $scalefactor=$maxThumbSize/$fileWi +dth; } else { $scalefactor=$maxThumbSize/$fileHeight; } $thumbWidth = int($fileWidth*$scalefactor); $thumbHeight = int($fi +leHeight*$scalefactor); } else { $thumbWidth=$fileWidth; $thumbHeight=$fileHeight; } $thumbnailImage = new GD::Image($thumbWidth, $thumbHeight); $thumbnailImage->copyResampled($sourceImage,0,0,0,0,$thumbWidth,$thumb +Height,$fileWidth,$fileHeight); $thumbPath = $thumbFolder . $S . $imageBase . "-" . $fileWidth . "x" . + $fileHeight . ".jpg"; if (-f $thumbPath) { unlink("$thumbPath"); } open(THUMB, ">$thumbPath") or &error('Cannot Open New Thumbnail'); if ($opsys eq "dos") { binmode THUMB; } else { flock(THUMB, 2); } if ((($fileWidth gt $maxThumbSize) || ($fileHeight gt $maxThumbSize)) +|| ($retype eq "yes")) { print THUMB $thumbnailImage->jpeg(75); } else { print THUMB $sourceImage->jpeg(75); } close(THUMB) or &error('Cannot Close New Thumbnail'); chmod(0644, $thumbPath); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Corrupted data problem in copyResampled using GD.pm
by graff (Chancellor) on Feb 10, 2004 at 06:47 UTC | |
by BUU (Prior) on Feb 10, 2004 at 07:33 UTC | |
by brianviehland (Initiate) on Feb 10, 2004 at 21:23 UTC | |
by BUU (Prior) on Feb 11, 2004 at 06:06 UTC | |
|
Re: Corrupted data problem in copyResampled using GD.pm
by graff (Chancellor) on Feb 11, 2004 at 00:56 UTC | |
by brianviehland (Initiate) on Feb 11, 2004 at 08:09 UTC |