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

Understanding GD.pm

Status
Not open for further replies.

calabama

Programmer
Feb 19, 2001
180
US
In trying to understand the basics of creating thumbnails using GD.pm. I found a simple script that I copied and called thumbnail.cgi(CHMOD755), the code seemed to make sense.
So I placed a jpg file directly into the cgi folder(CHMOD755) and I plugged in the src file name and nothing happens. Not even a print statement, just a blank white page.
I am very frustrated. I just wanted to see how the thumbnail creation works.
Thanks for your time
Cal
Code:
#!/usr/local/bin/perl


use GD;
print "Content-type: text/html\n\n";

my $maxheight = 100;
my $maxwidth = 100;
my $srcimage = GD::Image->newFromJpeg("churchmiddle.jpg");
my ($srcW,$srcH) = $srcimage->getBounds();
my $wdiff = $srcW - $maxwidth;
my $hdiff = $srcH - $maxheight;
my $newH; my $newW;

if ($wdiff > $hdiff) {
    $newW = $maxwidth;
      $aspect = ($newW/$srcW);
      $newH = int($srcH * $aspect);
  } else {
     $newH = $maxheight;
     $aspect = ($newH/$srcH);
      $newW = int($srcW * $aspect);
 }
print "converting $srcW:$srcH to $newW:$newH\n";

my $newimage = new GD::Image($newW,$newH);
$newimage->copyResized($srcimage,0,0,0,0,$newW,$newH,$srcW,$srcH);
open(FILE, ">test.jpg") || die "Cannot open churchmiddle.jpg: $!\n";
print FILE $newimage->jpeg;
In the begining
Let us first assume that there was nothing to begin with.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top