php imagerotate()在png上破坏alpha? [英] php imagerotate() ruins alpha on png?

查看:82
本文介绍了php imagerotate()在png上破坏alpha?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在b头,这很简单.

I've been bashing my head agains something simple..

// ....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

给我这个:

祝你好运!

完美的alpha png合成...

perfect alpha png composite...

现在我想旋转它,所以我不用$ out = $ pasteboard来这样做:

Now I want to rotate it, so instead of the $out=$pasteboard i do this:

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

header('Content-type: image/png');
imagepng($out);

可悲的是,这给了我:

BOOOO!

我尝试将颜色设置为:

imagerotate($pasteboard,5,0x00000000,0);

也是最后一个属性,例如:

also the last attr like:

imagerotate($pasteboard,5,0x00000000,1);

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

new empty images sampled etc etc...

没有骰子....

任何人都可以帮忙吗?

推荐答案

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

I'm answering my question simply because I've tried 10-15 suggestions i've seen allover the web all of which offering 'nearly' right solutions but nothing exact, Also I've seen this question posted a few places now, and hopefully if anyone reaches this page in future it would be best to show the solution as the direct answer.

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

MASSIVE thanks to @cristobal for the help and efforts, if I could vote you up any more I would !

诀窍似乎是:

//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);

生成此代码(即使您看不到白页,它也具有完美的alpha值):

produces this (it has a perfect alpha even though you cant see against the white page):

这不是我一生中最有趣的5个小时...希望它将阻止其他人遭受同样的痛苦.

REALLY not the most fun 5 hrs of my life... hopefully it will stop someone else going through the same pain..

这篇关于php imagerotate()在png上破坏alpha?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆