PHP - 图像上的蒙版多边形
大家好(这是我的第一篇文章),
我正在尝试找出一种从图像中裁剪多边形的方法。我一直在阅读其他类似的代码。似乎大多数代码都基于以下过程:
- 调整图像大小以适合多边形形状的宽度和高度,
- 创建相同大小的不寻常颜色的空白图像,
- 覆盖多边形形状中的透明像素,
- 覆盖在调整大小的图像上将
- 不寻常的颜色设置为透明...
我的问题是我不希望代码依赖于原始图像中不存在的不寻常的颜色。有谁有更好的方法或一些代码,我可以用它来检查图像中是否存在不寻常的颜色。
顺便说一句,一旦我裁剪了它们,我希望仅在形状的顶部和左侧添加边框,并在角落添加三个像素,以实现圆角效果......如果有人对此有任何想法,那么也请发帖。
Hi Everyone (this is my first post),
I am trying to figure a way of cropping a polygon out of an image. I have been reading other similar code. It seems that most code is based around the following process:
- Resize the image to fit the width and height of the polygon shape,
- Create a blank image of an unusual colour the same size,
- Overlay transparent pixels in the shape of the polygon,
- Overlay that on to the resized image
- Set the unusual colour to be transparent...
My problem is I do not want the code to be reliant on the unusual colour not being in the original image. Does anyone have a better method or some code which I can use to check if the unusual colour is in the image.
On a side note once I have cropped them I am looking to add a border only around the top and the left sides of the shape and three pixels in the corners to achieve a rounded corner effect... if anyone has any ideas about that then please also post.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在不同的图像(称为蒙版)上以黑白(以及介于两者之间的布雷值)绘制多边形,则可以使用 WideImage 库的 applyMask。
看:
- http://wideimage.sourceforge.net/
-
If you draw the polygon in black-white (and brey values between) on a different image (called mask), you can use applyMask of the WideImage library.
See:
- http://wideimage.sourceforge.net/
- http://wideimage.sourceforge.net/wp-content/current/demo/index.php?demo=applyMask&output=preset%20for%20demo&colors=255&dither=&match_palette=
另一种方法是将大图像切成 4 部分......
顶部部分,
左侧和右侧是蒙版后图像左侧和右侧的部分
和底部
并重新组合它们。
但这需要一些代码和计算。
an alternative way would be to cut the big image in 4 parts ...
a top part,
left side and right side that are the parts on the left and right of the image afte the mask
and bottom part
and recompose them.
But that would require a bit of code and calculations.