Resizing images with white background using php and GD.

Discussion in 'Programming/Scripts' started by Angelito, Jul 14, 2008.

  1. Angelito

    Angelito New Member

    Hello community,

    I am using the following php script to resize .gif images using the GD library; It works very decent:
    $src_img =imagecreatefromgif("bulb_gif.gif");
    $srcsize = getimagesize('bulb_gif.gif');
    $dest_x = 200;
    $dest_y = (200/ $srcsize[0]) * $srcsize[1];//resize ratio.
    $dst_img = imagecreatetruecolor($dest_x, $dest_y);

    // Resize image
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]);

    // Output image
    header("content-type: image/gif");
    imagegif($dst_img);//final image

    // Destroy images


    The problem is when resizing images with white background (not transparency), after the script is executed the image background turns not being 100% white (255,255,255). Links:

    Original .gif file:
    Resized image:

    You can notice the difference between the resized image and the page background. This varies from LCD to LCD, I can tell the difference in my main screen is about 75%, in other screens I have around this is about 90%.

    Any help will be gently apreciated.

    Thank you.
  2. burschik

    burschik New Member

    You are using an interpolated resizing operation. Either use a non-interpolating resizing operation instead, or do not create a true colour destination image.
  3. metalass

    metalass New Member


    Can you clarify what does it mean, non-interpolating resizing. Does it means to use imagesetinterpolation function ( or another php function?

    Can you write an example of code, please!
    It's very important. I have not found any other discussions of this problem all around the Internet.

Share This Page