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.


In reply to GD resize problems by horbor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.