Solved

Perl GD Image manipulation problem

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

13 Experts available now in Live!

Get 1:1 Help Now