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

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
User avatar
HongThao
Forum Newbie
Posts: 3
Joined: Thu Oct 18, 2007 11:46 pm
Contact:

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

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

are you using imagecopyresized() or imagecopyresampled() ?

Hint: imagecopyresampled() produces MUCH better output, but is slightly slower.
User avatar
HongThao
Forum Newbie
Posts: 3
Joined: Thu Oct 18, 2007 11:46 pm
Contact:

Post 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);
Lukaslo
Forum Newbie
Posts: 1
Joined: Sat Dec 01, 2007 6:07 am

Post by Lukaslo »

Download this script and check the code: Online Image Resizer
Post Reply