Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Perl GD Image manipulation problem

Posted on 2006-11-16
1
256 Views
Last Modified: 2012-05-05
Im running windows 2000 server with active perl installed.

Im trying to create a small app that takes a jpg image and copys it 4 times mergin into one image.
And makes a thumbnail of the image.

I am getting weird results...

Original image
http://www.thespenceroutfit.com/cgi-bin/Flyer/Test2.jpg

http://www.thespenceroutfit.com/cgi-bin/Flyer/Flyer.cgi


use GD;
my $maxheight = 350;
my $maxwidth = 350;
my $srcimage = new GD::Image->newFromJpeg("Test2.jpg") || die;
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);
 }

 $BigH = ($srcH * 2);
 $BigW = ($srcW * 2);
 my $newimage = new GD::Image($BigW,$BigH) || die;
$newimage->copy($srcimage,0,0,0,0,$srcW,$srcH);
$newimage->copy($srcimage,$srcW,$srcH,0,0,$srcW,$srcH);

# code for thumbnail $newimage->copyResized($srcimage,0,0,0,0,$newW,$newH,$srcW,$srcH) ;
 
 open(FILE, ">index1.jpg") || die "Cannot open index1.jpg: $!\n";
 print FILE $newimage->jpeg(80) ;
 close FILE;
 
print '<br><br><img src="http://www.thespenceroutfit.com/cgi-bin/Flyer/index1.jpg">';
exit;
0
Comment
Question by:tad91030
1 Comment
 
LVL 17

Accepted Solution

by:
mjcoyne earned 250 total points
ID: 17962089
Try:

 open(FILE, ">index1.jpg") || die "Cannot open index1.jpg: $!\n";
 binmode FILE;
 print FILE $newimage->jpeg(80) ;
 close FILE
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question