dub said:
Hi folks... I'm trying to find a perl script that I can hopefully
reference from a http link (like
http://www.mysite.com/cgi-bin/resize.cgi?image=jpeg.jpg&width=100). I
need it to shrink down uploaded user profile pics to a maximum width.
I have a lame server which won't let me install Image magick, but it
does have NETPBM and GDLib (though I don't want to use PHP for this).
I have exhausted all search engine possibilities... any help would be
VASTLY, Greatly appreciated.
Here is some code I used for a demo that uses the Perl<->GD bindings
(GD.pm). It only does jpeg, but it would be easy to modify. You can see it
work at:
http://waveright.homeip.net/products/demos/jpg2thumb/
#!/usr/bin/perl
use warnings;
use strict;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use CGI; my $q = CGI->new();
use GD;
use Image::GD::Thumbnail;
if ( $q->param ) {
my $fh = $q->upload('theImage');
# Load your source image
my $srcImage = GD::Image->newFromJpeg( $fh );
# Create the thumbnail from it, where the biggest side is
$q->param('theSize') px
my($thumb,$x,$y) = Image::GD::Thumbnail::create($srcImage,
$q->param('theSize'));
print $q->header(-type => 'image/jpeg');
binmode( STDOUT );
print $thumb->jpeg;
} else {
print $q->header(-type => 'text/html');
print $q->start_html( -title => 'jp(e)g to thumbnail converter' );
print $q->h1( 'jp(e)g to thumbnail converter' );
print $q->br( { width => '75%' } );
print $q->div( 'jp(e)g to thumbnail converter' );
print $q->div( ' ' );
print $q->div( 'Enter A jp(e)g File Name: ' );
print $q->start_multipart_form();
print $q->div(
'Size in pixels you wish the longest side to be: ',
$q->textfield(
-name => 'theSize',
-size => 3,
-default => '100',
-override => 1,
)
);
print $q->div( ' ' );
print $q->div( $q->filefield('theImage', '', 50) );
print $q->div( ' ' );
print $q->table(
$q->Tr(
$q->td( $q->submit ),
$q->td( $q->reset )
)
);
print $q->endform;
print $q->end_html;
}
Enjoy,
Todd W.