Forum Moderators: coopster

Message Too Old, No Replies

image resample problem with GDS

         

scorpion

10:27 pm on Apr 25, 2003 (gmt 0)

10+ Year Member



I've tried everything to resize & resample a image from something like from 169x214 to 88x111 and it just doesn't work. The resulting image is a weird...you can see the outlines but the pixels are like large blobs - kind of like seeing a picture through a pixelation filter...I tried the imagecreatefromtruecolor for the destination, 0,0 for coordinates, but nothing works, always looks like this...Anybody else have problems?

andreasfriedrich

12:32 pm on Apr 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you check out the Image upload and Thumbnail Generator [webmasterworld.com] in the Bag-O-Tricks for PHP II [webmasterworld.com]?

Andreas

Birdman

1:10 pm on Apr 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Scorpion,

Can you post the image function you are using?

Birdman

hello A.F.

scorpion

3:22 pm on Apr 26, 2003 (gmt 0)

10+ Year Member



$image = "headshot.jpg";
$thumbw = 88;
$thumbh = 111;
$size = getimagesize($image);
$scale = min($thumbw/$size[0], $thumbh/$size[1]);
$width = (int)($size[0]*$scale);
$height = (int)($size[1]*$scale);
$deltaw = (int)(($thumbw - $width)/2);
$deltah = (int)(($thumbh - $height)/2);

$src_img = ImageCreateFromJPEG($image);
$dst_img = ImageCreateTrueColor($thumbw, $thumbh);

ImageCopyResampled($dst_img, $src_img, $deltaw, $deltah, 0, 0, $width, $height, ImageSX($src_img),ImageSY($src_img));
imagejpeg($dst_img, "headshot_resample.jpg", 86);

It's right from the snippet in the php documentation. It just does not work...the original image is fine, the resultant image is this pixelated mess everytime. I even tried the imageresamplebicubic..nothing seems to work...

scorpion

3:24 pm on Apr 26, 2003 (gmt 0)

10+ Year Member



the bag of tricks example uses imageresized, so I presume it doesn't resample it...so it would look like just specifiying an arbitrary img src tag height and width? or its different?

andreasfriedrich

4:14 pm on Apr 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



imagecopyresized [php.net] and imagecopyresampled [php.net] both have the same signature. If you have gdlib2+ installed you can simply replace imagecopyresized [php.net] with imagecopyresampled [php.net].

Andreas

Hi Birdman :)