X
X
XenK2015-03-14 11:05:14
PHP
XenK, 2015-03-14 11:05:14

Why does saving the alpha channel in GD not work?

It is necessary to save the alpha channel of the image (.png).
Tried this code:

$up = ImageCreateFrompng('up.png');
imagealphablending($up, false);
imagesavealpha($up, true);
imagecopy($pic, $up, 200, 200, 0, 0, 145, 343);

The image is still superimposed with a white background, what could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
XenK, 2015-03-14
@XenK

I solved the problem by the fact that it was necessary to save both images in PNG-24.

O
olamedia., 2015-03-14
@w999d

Probably need to include alpha in $pic before this

$up = ImageCreateFrompng('up.png');
$pic = imagecreatetruecolor(400, 400);
imagealphablending($pic, false);
// imagesavealpha($pic, true); // true alpha channel
imagecopy($pic, $up, 200, 200, 0, 0, 145, 343);//, 145, 343
imagesavealpha($pic, true); // PNG-24
imagepng($pic, 'pic.png');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question