Solved

Perl GD Image manipulation problem

Posted on 2006-11-16
1
255 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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 …
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now