imagerotate() 中的背景透明度
自过去 2 天以来,我尝试使用 imagerotate() PHP-GD 函数旋转图像后向背景添加透明度。
但是,令我非常失望的是,它根本不起作用。
它只是在其背后提供黑色背景。
这是我的代码 -
$patchImageS = 'image.png'; // the image to be patched over the final bg $patchImage = imagecreatefrompng($patchImageS); // resource of image to be patched $patchImage = imagerotate($patchImage, 23, 0, 0); imagepng($patchImage,'tt.png');
我尝试将函数中传递的参数更改为
imagerotate($patchImage, 23, 5, 0);
imagerotate($patchImage, 23, 0, 5);
任何帮助将不胜感激。
Since last 2 days, I was trying to add transperancy to the background after rotating an image using imagerotate() PHP-GD function.
But, to my great disappointment, it's not working at all.
It's just giving out a black background behind it.
Here's my code -
$patchImageS = 'image.png'; // the image to be patched over the final bg $patchImage = imagecreatefrompng($patchImageS); // resource of image to be patched $patchImage = imagerotate($patchImage, 23, 0, 0); imagepng($patchImage,'tt.png');
I tried to change the parameters being passed in function to
imagerotate($patchImage, 23, 5, 0);
imagerotate($patchImage, 23, 0, 5);
Any help would be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在完成了 99% 的答案之后,这是我找到的解决方案:
这里的关键是将你的 imagecolorallocatealpha() 包含在你的 imagerotate() 调用中......
After a number of 99% finished answers, here's the solution I've found:
The key here is to include your imagecolorallocatealpha() in your imagerotate() call...
在 php 文档中查找 imagesavealpha() - 我认为这就是您正在寻找的。
编辑:这是一个例子:
look for imagesavealpha() in the php-documentation - i think this is what you are looking for.
EDIT: here's an example:
对于任何遇到背景上有黑条的
imagecopyresampled
或imagerotate
问题的人,我在这里找到了一个代码示例:https://qna.habr.com/q/646622#answer_1417035
For anyone having problems with
imagecopyresampled
orimagerotate
with black bars on background, I have found a code example here:https://qna.habr.com/q/646622#answer_1417035