in reply to Re: Dymanically Generated Images in Website
in thread Dymanically Generated Images in Website
I hope this is useful to someone. Enjoy!#!/usr/local/bin/perl # Usage: http://www.yoururl.com/cgi-bin/image_resize.cgi?FILE=/path/to +/image.jpg&SIZE=300 use Image::Resize; use Image::Size; use CGI::Simple; my $q = new CGI::Simple; my $file = $q->param('FILE'); # Path to file on server file system my $size = $q->param('SIZE'); # Desired size of image my ($x, $y, $type) = imgsize($file); $size = ($x > $y) ? $x : $y if (($x < $size) || ($y < $size)); # Will not scale greater than 100% my $image = Image::Resize->new($file); my $gd = $image->resize($size, $size, 1); # 1 = maintain aspect ratio binmode STDOUT; if ((uc($type) eq 'JPG') || (uc($type) eq 'JPEG')) { print(qq|Content-Type: image/jpeg\n\n|); print $gd->jpeg(); } elsif (uc($type) eq 'PNG') { print(qq|Content-Type: image/png\n\n|); print $gd->png(); } elsif (uc($type) eq 'GIF') { print(qq|Content-Type: image/gif\n\n|); print $gd->gif(); }
|
|---|