用php旋转png图像后如何获得透明背景?
所以我有 png 图像,我旋转它,但我得到黑色背景..或者如果我执行白色的颜色代码,我会得到白色..我尝试这样做..
$trans = imagecolorallocatealpha(image, 0, 0, 0, 127);
imagerotate($image, $degree, $trans)
我也尝试过..
$trans = imagecolorallocatealpha($image, 255, 255, 255, 127);
有人可以帮助我吗?
这是我的代码..如果我将 allocatealpha 更改为 0, 0, 255, 0 那么它会变成蓝色。但使用 0, 0, 0, 127 时它仍然是黑色的。
function rotate($degrees) {
$image = $this->image;
imagealphablending($image, false);
$color = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefill($this->image, 0, 0, $color);
$rotate = imagerotate($image, $degrees, $color);
imagesavealpha($image, TRUE);
$this->image = $rotate;
}
So I have png image and I rotate it but i get a black background.. or if i do the color code ofr white i get white.. I tried doing this..
$trans = imagecolorallocatealpha(image, 0, 0, 0, 127);
imagerotate($image, $degree, $trans)
i have also tried..
$trans = imagecolorallocatealpha($image, 255, 255, 255, 127);
Can someone help me out?
here is my code.. if i change allocatealpha to 0, 0, 255, 0 then it goes blue. but with 0, 0, 0, 127 its still black.
function rotate($degrees) {
$image = $this->image;
imagealphablending($image, false);
$color = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefill($this->image, 0, 0, $color);
$rotate = imagerotate($image, $degrees, $color);
imagesavealpha($image, TRUE);
$this->image = $rotate;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
根据下面的正确评论,这应该是:
As per the correct comment below, this should be:
确保将
imagesavealpha
设置为 TRUE 以保留透明度。 http://www.php.net/manual/en/function.imagesavealpha.phpimagesavealpha($image, TRUE);
Make sure you set
imagesavealpha
to TRUE in order to preserve transparency. http://www.php.net/manual/en/function.imagesavealpha.phpimagesavealpha($image, TRUE);
你试过这个吗?
imagecolortransparent
希望我理解你的问题!
Have you tried this?
imagecolortransparent
Hope i understood your question!
您可以尝试以下操作:http://www.exorithm.com/algorithm/view/rotate_image_alpha
You can try this: http://www.exorithm.com/algorithm/view/rotate_image_alpha
这就是我正在使用的,这对于具有透明背景的 .png 文件非常有用。击掌!
This is what I am using, this work great for .png files with transparent backgrounds. High fives!