0

I'm trying to output an image with PHP, but when I do it, it won't look as the original image. The original image has transparent background, and the outputted image has some weird background which "kills" the image.

This is my code:

<?php
$image = imagecreatefrompng('./logo2.png');
$imagesize = getimagesize('./logo2.png');
header('Content-type: ' . $imagesize['mime']);
imagepng($image);
imagedestroy($image);

If you need anything else in order to determine the issue, please tell me.

Omer Aviv
  • 286
  • 3
  • 20

1 Answers1

0

Add alpha blending:

<?php
$image = imagecreatefrompng('./logo2.png');
$imagesize = getimagesize('./logo2.png');
header('Content-type: ' . $imagesize['mime']);

imagealphablending($image, true);
imagesavealpha( $image, true );

imagepng($image);
imagedestroy($image);

This was answered for example here:

Community
  • 1
  • 1
olegsv
  • 1,422
  • 1
  • 14
  • 21