PHP - Mask polygon over image

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 07:31:03

问题


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.


回答1:


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=




回答2:


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.



来源:https://stackoverflow.com/questions/1544621/php-mask-polygon-over-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!