PHP 中的透明圆角
是否可以使用 PHP 为动态图像创建透明角?我认为这是可能的,但我缺少一个在复制图像时保留 alpha 值的函数。
我的想法是创建一个相同宽度和高度的图像,然后应用透明角,但随后我需要保留 Alpha 通道并仅在该蒙版上复制图像,使透明仍然透明,但颜色更改为复制的图像(反之亦然) ,在图像上放置掩模)。
是否可以这样做?如果有的话,命令是什么?
更新:感谢您对此提供帮助。那是前一段时间了,我忘了,但如果有人遇到这个问题来寻找解决方案,请访问这个:http://www.pc-siete.g6.cz/galery.html 。我制作了渐变、径向渐变和圆角的函数,所以请随意使用:)。我并没有真正在我的网站上使用它,但准备好它们是很好的。
由于某种原因,下载的文件中只有广告。现在它存储在 zip 中并且可以正确下载。
Is it possible to create transparent corners for an image on fly with PHP? I think that it would be possible, but I am missing a function that would preserve alpha values when you copy your image.
My idea was to create an image of same width and height, then apply transparent corners, but then I need to preserve the alpha channel and just copy image on that mask, leaving transparent still transparent, but colors changed to copied image (or vice versa, put mask on image).
Is it possible to do that and what are commands for that if there are any?
Update: Thanks for helping with this. It was some time ago, and I forgot but if anybody cross this question to find a solution just visit this one: http://www.pc-siete.g6.cz/galery.html . I made functions for gradient, radial gradient and also those rounded corners so feel free to use :) . I'm not really using it on my webstie, but it's good to have them prepared.
For some reason the downloaded file had just ad in it. Now it's stored inside zip and downloads properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
据我所知,没有内置函数可以做到这一点。不过,您可以按照以下方式自己创建一个:
As far as I know there is no built-in function to do this. However you can create one yourself along these lines:
我刚刚在 PHP 中使用 ImageMagick 创建了这个函数,它完全符合我的要求。您需要设置
TEMP_DIR
常量,并在执行路径上放置convert
可执行文件。I just created this function using ImageMagick in PHP which does exactly what I wanted. You need to set the
TEMP_DIR
constant and have theconvert
executable on your execution path.与其尝试重新发明轮子,不如使用 PHP 缩略图,它将为您完成一切:
Instead of trying to reinvent the wheel use the PHP thumbnailer which will make everything for you:
请参阅 ImageMagick 参考。是的,你所描述的一切都是可能的,所有的工具都在那里。
See the ImageMagick reference. Yes, everything you describe is possible, all the tools are there.