Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Perl GD Image manipulation problem

Posted on 2006-11-16
1
Medium Priority
?
262 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
[X]
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
1 Comment
 
LVL 17

Accepted Solution

by:
mjcoyne earned 1000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans

715 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