PHP-在图像上遮罩多边形 [英] PHP - Mask polygon over image

查看:223
本文介绍了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:

  • 调整图像大小以适合多边形形状的宽度和高度,
  • 创建大小相同的不寻常颜色的空白图像,
  • 以多边形的形状覆盖透明像素,
  • 将其覆盖到调整后的图像上
  • 将不寻常的颜色设置为透明...

我的问题是我不希望代码依赖于原始图像中没有的异常颜色.有没有人有更好的方法或一些代码可用来检查图像中是否存在异常颜色.

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.

推荐答案

如果在另一幅图像(称为蒙版")上以黑白(介于其间的灰度值)绘制多边形,则可以使用WideImage库的applyMask.

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.

请参阅: - http://wideimage.sourceforge.net/ -

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=

这篇关于PHP-在图像上遮罩多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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