How to merge PNGS with alpha channels into one larger image?
I am trying to layer these:
into this:
But what I keep getting is this:
This is the relevant code, Im not sure what Im missing:
$sig_background = imagecreatefrompng("sanctum-signature.png");
imagealphablending($sig_background, false);
imagesavealpha($sig_background, true);
$sig_gamertile = imagecreatefrompng($gamertile_masked_file);
imagealphablending($sig_gamertile, false);
imagesavealpha($sig_gamertile, true);
$sig_gametile = imagecreatefrompng($gametile_masked_file);
imagealphablending($sig_gamertile, false);
imagesave开发者_如何学Calpha($sig_gamertile, true);
imagecopymerge($sig_background, $sig_gamertile, 175, 2, 0, 0, 64, 64, 100);
imagecopymerge($sig_background, $sig_gametile, 342, 20, 0, 0, 64, 64, 100);
If any more information is missing, please let me know and Ill try to fill in the blanks. Thank you for your time.
edit - here are links to the files (hosted on photobucket) gamertile gametile
There's a typo in your code, is it a copy/paste error or a real bug?
You do:
$sig_gamertile = imagecreatefrompng($gamertile_masked_file);
imagealphablending($sig_gamertile, false);
imagesavealpha($sig_gamertile, true);
And then:
$sig_gametile = imagecreatefrompng($gametile_masked_file);
But straight afterwards, you continue to call functions on $sig_gamertile
instead of $sig_gametile
:
imagealphablending($sig_gamertile, false);
imagesavealpha($sig_gamertile, true);
Obviously radically renaming some vars would help guard against this.
The line:
imagealphablending($im, false);
disables alpha blending. Use true instead of false.
精彩评论