How to do four point distort with Imagemagick

人盡茶涼 提交于 2019-12-08 06:01:43

问题


I want to place a logo on a image. I have 4 (x,y) coordinates. The logo should be placed between this area only with some skew effect as given below.


回答1:


It is always best to provide clean separate input imagery (in a addition to your result) and your ImageMagick version and platform.

Nevertheless, I cropped out the two images as:

Then I measured the corner coordinates of the G image clockwise from the top left corner.

Then I measured the colored circle coordinates in similar order (green, red, pink, blue).

Then I did the +distort perspective and composited the two images. The sequence of coordinates is: inx1,iny1 outx1,outy1 .... inx4,iny4 outx4,outy4, where the G image is the in and the bag image is the out.

Here is the command in unix ImageMagick 6 syntax. For Windows remove the \s. For ImageMagick 7, use "magick" rather than "convert"

convert bag.png \( G.png -virtual-pixel none +distort perspective "0,0 75,280  116,0 155,311  116,119 141,367  0,119 64,329" \) -layers flatten +repage result.png

Reference: http://www.imagemagick.org/Usage/distorts/#perspective

EDIT:

If you make the white background of the G image transparent, then it will look better.

convert bag.png \( G.png -fuzz 15% -transparent white -virtual-pixel none +distort perspective "0,0 75,280  116,0 155,311  116,119 141,367  0,119 64,329" \) -layers flatten +repage result2.png



来源:https://stackoverflow.com/questions/50491068/how-to-do-four-point-distort-with-imagemagick

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