phppnggd2

Converting a png to jpg with GD2.. transparency problem


I have an image.png with white background and some trasparceny over it.

I tried this to convert the image into jpg:

$data = file_get_contents('image.png');
$resource = imagecreatefromstring($data);
imagejpeg($resource); //> I TRIED WITH QUALITY = 100 TOO

Problem is where the png got the trasparency now the jpg got a pretty huge black zone. This is how jpg looks:

http://img861.imageshack.us/img861/20/context.jpg

Any way to solve the problem?

Edit1:

As suggested by Abiusx I tried this too:

$data = file_get_contents('image.png');
$resource = imagecreatefromstring($data);
imagealphablending($data, false);
imagesavealpha($data, true);
imagejpeg($resource);

But the result was the same. Please note The source .png image is:


(source: tipradar.com)

Thanks to Patrick comment: here the trick: GD! Converting a png image to jpeg and making the alpha by default white and not black


Solution

  • Answer here:

    GD! Converting a png image to jpeg and making the alpha by default white and not black