Page 1 of 1

How to resize image by GD in PHP without color noise?

Posted: Fri Oct 19, 2007 12:11 am
by HongThao
Hi all,

I need to change image's size by GD in PHP. An fix image at the first layer, the second

layer has an transparent image with white background. We can't see this white background

because I did:

Code: Select all

$trans = imagecolortransparent($layer_2,$white);
There are 2 buttons "Zoom in" and "Zoom out" that user can change image size whatever

they want. My problem is:
After changing the first time it's fine. Continue to change one more time the image's

background has color noise.
Does anyone have idea that help to solve the background color noise?
Thanks so much,
Hong Thao

Posted: Fri Oct 19, 2007 12:35 am
by Kieran Huggins
are you using imagecopyresized() or imagecopyresampled() ?

Hint: imagecopyresampled() produces MUCH better output, but is slightly slower.

Posted: Fri Oct 19, 2007 3:46 am
by HongThao
Yes, I use imagecopyresampled() like this to resize

Code: Select all

// Resize the original image
    $imageResized = imagecreatetruecolor($new_width, $new_height);
    $imageTmp     = imagecreatefrompng ($originalImage);
    imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

Posted: Sat Dec 01, 2007 6:09 am
by Lukaslo
Download this script and check the code: Online Image Resizer