in reply to GD.pm copyResized / copyResampled errors

Ah I see, it's line 173 of your code! (Abigail joke?) Just kidding. :-)

Can you show us your code? Otherwise we can only guess what's happenning... The copyResized and copyResampled methods will stretch or shrink the image to fit the given thumbnail dimension, but could be something to do with not closing the image file properly? Binmode on Windows platform?

  • Comment on Re: GD.pm copyResized / copyResampled errors

Replies are listed 'Best First'.
Re: Re: GD.pm copyResized / copyResampled errors
by brianviehland (Initiate) on Feb 04, 2004 at 01:49 UTC
    I've updated the post. If anyone has any idea why the image is being corrupted, please let me know...
      I wrote the following program to test the copyResampled function in GD, and I have confirmed that the 'corruption' is really a bug in the GD library, most likely due to rounding errors (because of the resampling algorithm used) and I am getting an 'extra' line in both X and Y directions.

      use strict; use warnings; use IO::File; use GD; my $src = GD::Image->newFromJpeg('077.jpg'); my ($srcw, $srch) = $src->getBounds(); # (550, 413) my $destw = int ($srcw/3); my $desth = int ($srch/3); my $dest = GD::Image->new($destw-1, $desth-1); $dest->copyResampled($src,0,0,0,0,$destw,$desth,$srcw,$srch); my $f = new IO::File "078.jpg", "w" or die "Can not create image: $!"; binmode $f; print $f $dest->jpeg(80);

      To get around this problem, I just created the target canvas 1 pixel smaller in both X and Y directions. I was actually expecting the library to core dump on the resampling because the destination width and height are 1 pixel greater than the canvas, but the GD library has clipped the target bitmap properly. So excellent that's the fix.

      Another fix is to leave the target canvas unchanged, but add 1 to both destination width and height in the resample function, which also gives a good result.
      my $dest = GD::Image->new($destw, $desth); $dest->copyResampled($src,0,0,0,0,$destw+1,$desth+1,$srcw,$srch);

        Well, that is one problem, but that wasn't the trouble I was having... Here you can see the original and the thumbnail that I ended up with: http://viehland.org/gd-images/index.html It's like the program forgets what it's doing and it just quits in the middle...