0

I created a white background and add a Png image. But upon doing trails & error still the png image show light backgroung color , it should be 100% transparent with no bg color.

This is my code after doing trails and error, but it still shows a ligh background color in png image. It should be 100% transparent. I tried a lot guys but not got any solutions upto now.

$img_h = imagesy($image);
$img_w = imagesx($image);

// create new image (canvas) of proper aspect ratio
$img = imagecreatetruecolor($canvas_w, $canvas_h);

$background = imagecolorallocate($img, 255, 255, 255);

imagefill($img, 0, 0, $background);

$xoffset = ($canvas_w - $img_w) / 2;
$yoffset = ($canvas_h - $img_h) / 2;

imagealphablending($img, true);
imagesavealpha($img, true);
imagecopyresampled($img, $image, $xoffset, $yoffset, 0, 0, $img_w, $img_h, $img_w, $img_h); 

I expected png image will be seen transparent on white background. But the code adds a light background color on png image. Image preview - Output result image

Nic3500
  • 8,144
  • 10
  • 29
  • 40
Tech Cruz
  • 1
  • 1

0 Answers0