Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Upload and Resize

Status
Not open for further replies.

MaxGeek

Technical User
Jan 8, 2004
52
0
0
US
Does anyone know a good tutorial or download for a simple image upload and resize PERL script?
 
image upload can be done with any form set to enctype=multipart, and using the PERL CGI module.

and I found this that usues the GD module.
Code:
#!/usr/bin/perl
    sub jpg_resize
    {
    use GD;
    #settings--------------------------------------
    my $source_file = "";
    my $target_file = "";
    my $jpeg_quality = 60;	#Quality
    my $max_sizex = 220;	#max picturewith
    my $max_sizey = 220;	#max pictureheight
    #----------------------------------------------
    $source_file = shift();
    $target_file = shift();
    GD::Image->trueColor(1);	#improves quality
    my $bildle = newFromJpeg GD::Image($source_file, 1) || die "could not open image.";	#Bild ffnen...
    #find size-------------------------------------
    (my $width, my $height) = $bildle->getBounds();	#Mae herausfinden...
    if ($width > $height)
    {$max_sizey = $height / ($width / $max_sizex);}
    else
    {$max_sizex = $width / ($height / $max_sizey);}
    #create new picture (thumbnail)
    my $bild=newTrueColor GD::Image($max_sizex,$max_sizey);
    $bild->copyResized($bildle,0,0,0,0,$max_sizex,$max_sizey,$width,$height);
    $bild->interlaced('true');
    #save the new picture...
    open(DATEI ,">$target_file") || die "could not write image: $!";
    binmode DATEI;
    print DATEI ($bild->jpeg($jpeg_quality));
    close(DATEI);
    return('true');
    }

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top