"Ingo Weiss" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi all,

I need have my CGI scale images on the server, and I was wondering
whether there is a "standard" perl module that can do that (and possibly
other image manipulation tasks). I am looking for one that:

- is easy to understand and use
- is likely to be already installed on the server or so well known that
my hosting provider is likely to agree to install it for me.

If by "scaling" you mean making thumbnails, I once did this simple CGI
program that lets the user upload a jpeg file, uses Image::GD::Thumbnail to
resize the image, then sends it back to the user:

#!/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 50 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;
}



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to