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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GD.pm Whats wrong with my script?

Status
Not open for further replies.

davef101

MIS
Mar 3, 2006
34
GB
I'm getting a 500 Internal Server error with this script, any ideas?


#!/usr/bin/perl
use GD;
use strict;
use warnings;

&jpg_resize();

print "Content-type: text/html\n\n";
print "<html><body>Done</body></html>";
exit();

sub jpg_resize
{

#settings--------------------------------------
my $sourcefile = "oldpic.jpg";
my $targetfile = "newpic.jpg";
my $jpeg_quality = 60; #Quality
my $max_sizex = 220; #max picturewith
my $max_sizey = 220; #max pictureheight
#----------------------------------------------
$sourcefile = shift();
$targetfile = shift();
GD::Image->trueColor(1); #improves quality
my $bildle = newFromJpeg GD::Image($sourcefile, 1) || die "could not open image."; #Bild öffnen...
#find size-------------------------------------
(my $width, my $height) = $bildle->getBounds(); #Maße 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 ,">$targetfile") || die "could not write image: $!";
binmode DATEI;
print DATEI ($bild->jpeg($jpeg_quality));
close(DATEI);
return('true');
}
 
i think the error is here, but not sure:

my $bildle = newFromJpeg GD::Image($sourcefile, 1) || die "could not open image.";
 
Code:
    my $sourcefile = "oldpic.jpg";
    my $targetfile = "newpic.jpg";
is being overwritten with balnk values from the default array, @_;
Code:
    $sourcefile = shift();
    $targetfile = shift();
Try [print $sourcefile;] before your call to newFromJpeg, after deleting the shift lines above, or at least comment them out

HTH
--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
change this:

Code:
#!/usr/bin/perl
use GD;
use strict;
use warnings;

to:

Code:
#!/usr/bin/perl
use GD;
use strict;
use warnings;
[b]use CGI::Carp qw/fatalsToBrowser/;[/b]

Now fatal errors will display in the browser. If you still get a 500 error the script permissions are wrong or the very first line (the path to perl) is wrong. After the script is working remove or comment out that line I added.

- Kevin, perl coder unexceptional!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top