Perl Script to Resize Images .jpgs (and .gifs too)

D

dub

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.

Thanks
dubious
 
G

Gunnar Hjalmarsson

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

What you want can probably be written in a rather small Perl script
using the GD CPAN module.

If, OTOH, you are looking for a ready-to-go script, you have come to the
wrong place.
 
D

dub

Ahh yes I realize that one can be written using the available
libraries. What I'm looking for is indeed a ready to go script. Does
anybody know of one?

Thanks,
Dubious
 
G

Gunnar Hjalmarsson

[ Dear Dubious,
You replied to a message in the Usenet group comp.lang.perl.misc. Even
if you posted from an interface provided by Google, most readers use
other tools for reading Usenet groups. Hence it's very important to
provide some context when you reply to a message, or else people who
might be able to help won't have a clue what you are talking about.
Typically that's accomplished by quoting parts of the message you are
replying to. ]
Ahh yes I realize that one can be written using the available
libraries. What I'm looking for is indeed a ready to go script. Does
anybody know of one?

I don't. And personally I would write it rather than looking for it,
since it's a rather simple script you need.

Of course, if you don't know any Perl it _might_ be worth a try. ;-)
But, again, then you have come to the wrong place. You'd better look at
places like http://www.cgi.resourceindex.com/Programs_and_Scripts/Perl/
 
T

Todd W

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( '&nbsp;' );
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( '&nbsp;' );
print $q->div( $q->filefield('theImage', '', 50) );
print $q->div( '&nbsp;' );
print $q->table(
$q->Tr(
$q->td( $q->submit ),
$q->td( $q->reset )
)
);
print $q->endform;
print $q->end_html;
}

Enjoy,

Todd W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top