horbor has asked for the wisdom of the Perl Monks concerning the following question:
Hi! Hope it the right place to post my question. I have a problem resizing jpeg images. An image after resizing has grey pixels at its bottom. Everything is fine on another machine, and also there are no problems when using gd from PHP. I use Perl and I get is "Premature end of JPEG file" in apache log. The system is running under SuSE 9.2, Apache 2.2,gd 2.032, GD module 2.3. Here is the resulting image
Here is the code:
open ( UPLOADFILE, ">".$site->{cfg}{var}{full_content_path}.$site- +>{cfg}{images}{original_dir}.$sourcename ) or die "Cannot open image file $!"; binmode (UPLOADFILE); while ( <$filehandle> ){ print UPLOADFILE; } # proceed, convert if needed, resize etc. if (-e $site->{cfg}{var}{full_content_path}.$site->{cfg}{images}{o +riginal_dir}.$sourcename){ my $method = $gd_ext{$extension}; my $original = GD::Image->$method($site->{cfg}{var}{full_conte +nt_path}.$site->{cfg}{images}{original_dir}.$sourcename,1) or die "Can't load original $sourcename: $!"; # calculate new height multiplication factor my ($width, $height) = $original->getBounds(); my $factor = ($width > $height) ? ($height / $width) : ($heigh +t / $width); foreach my $pre(@prefix){ my ($w,$h) = split('x',$site->{cfg}{images}{$pre.'_wh'}); my $n_height=int($factor*$w); my $image = GD::Image->new($w, $n_height, 1); $image->copyResampled($original, 0, 0, 0, 0, $w, $n_height +, $original->width, $original->height); open(FH, ">".$site->{cfg}{var}{full_content_path}.$site->{ +cfg}{images}{$pre.'_dir'}.$pre.'_'.$filename.'.jpg') or die "Cannot open image file ".$pre."_$filename $!"; binmode(FH); print FH $image->jpeg(100); close(FH); }
Any help is appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: GD resize problems
by BrowserUk (Patriarch) on Jan 17, 2011 at 11:58 UTC | |
by horbor (Novice) on Jan 17, 2011 at 13:27 UTC | |
by horbor (Novice) on Jan 17, 2011 at 12:30 UTC | |
|
Re: GD resize problems
by Crackers2 (Parson) on Jan 17, 2011 at 14:30 UTC | |
by horbor (Novice) on Jan 17, 2011 at 15:14 UTC |