php imagerotate()在png上破坏alpha?

Ale*_*lex 3 php gd php-gd

我一直在抨击我的头脑简单......

// ....all prev code is fine.... 
$pasteboard =imagecreatetruecolor($imgs['bg']["width"],$imgs['bg']["height"]);
imagealphablending($pasteboard, false);
imagecopyresampled($pasteboard, $imgs['bg']["img"],0,0,0,0,$imgs['bg']["width"],$imgs['bg']["width"],imagesx($imgs['bg']["img"]),imagesy($imgs['bg']["img"]));
imagecopyresampled($pasteboard, $imgs['photo']["img"],20,20,0,0,$imgs['photo']["width"],$imgs['photo']["width"],imagesx($imgs['photo']["img"]),imagesy($imgs['photo']["img"]));
imagesavealpha($pasteboard,true);
//send it out
$out = $pasteboard;

header('Content-type: image/png');
imagepng($out);
//then garbage collection
Run Code Online (Sandbox Code Playgroud)

给我这个:

在此输入图像描述

HORAY!

完美的alpha png复合...

现在我想旋转它,所以代替$ out = $ pasteboard我这样做:

imagesavealpha($pasteboard,true);
//rotate it
$out = imagerotate($pasteboard,5,imagecolorexactalpha($pasteboard,255,255,255,50),0);

header('Content-type: image/png');
imagepng($out);
Run Code Online (Sandbox Code Playgroud)

遗憾地给了我这个:

在此输入图像描述

BOOOO!

我试过设置颜色像:

imagerotate($pasteboard,5,0x00000000,0);
Run Code Online (Sandbox Code Playgroud)

也是最后一个像:

imagerotate($pasteboard,5,0x00000000,1);
Run Code Online (Sandbox Code Playgroud)

新的空图像采样等等...

没有骰子....

有人可以帮忙吗?

Ale*_*lex 5

我正在回答我的问题,因为我已经尝试了10-15条建议,我已经在网上看到了所有提供"几乎"正确的解决方案,但没有确切的,我也看到这个问题现在发布了几个地方,并且希望如果有人将来到达此页面,最好将解决方案显示为直接答案.

非常感谢@cristobal的帮助和努力,如果我能投票给你,我会的!

诀窍似乎是:

//rotate it
$pasteboard = imagerotate($pasteboard,5,0XFFFFFF00,0); //<-- here must be RRGGBBAA, also last attr set to 0
imagesavealpha($pasteboard, true); // <-- then to save it... dont ask me why..
//send it out
header('Content-type: image/png');
imagepng($pasteboard);
Run Code Online (Sandbox Code Playgroud)

产生这个(它有一个完美的阿尔法,即使你看不到白页):

在此输入图像描述

真的不是我生命中最有趣的5小时......希望它会阻止别人经历同样的痛苦......