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

Discussion in 'Perl Misc' started by dub, Dec 12, 2005.

  1. dub

    dub Guest

    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
    dub, Dec 12, 2005
    #1
    1. Advertising

  2. dub wrote:
    > 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.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Dec 12, 2005
    #2
    1. Advertising

  3. dub

    dub Guest

    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
    dub, Dec 12, 2005
    #3
  4. [ 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. ]

    dub wrote:
    > Gunnar Hjalmarsson wrote:
    >> dub wrote:
    >>> 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.

    >
    > 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/

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Dec 12, 2005
    #4
  5. dub

    Todd W Guest

    "dub" <> wrote in message
    news:...
    > 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.
    Todd W, Dec 12, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    1
    Views:
    475
    Beauregard T. Shagnasty
    Apr 29, 2006
  2. Replies:
    1
    Views:
    583
    Travis Newbury
    Sep 13, 2006
  3. Waguih Boctor

    JPGs & GIFs not displaying

    Waguih Boctor, Oct 29, 2003, in forum: ASP General
    Replies:
    1
    Views:
    140
    Ray at
    Oct 29, 2003
  4. Replies:
    2
    Views:
    1,260
    Adrienne
    Feb 13, 2005
  5. VivekR
    Replies:
    1
    Views:
    80
    Yanick
    Aug 26, 2006
Loading...

Share This Page