Imagemagick skew image with 4 (x,y) coordinates

2020-07-29 06:22发布

问题:

I have 4 (x,y) coordinates between which I want place image as example given below.

The whole image must be placed within this area without cropping.

回答1:

Using this 800x600 balloon:

You can use a "Perspective Distort" like this:

convert balloon.jpg -matte -virtual-pixel transparent  \
  -distort Perspective '0,0,50,0 0,599,100,599 800,0,750,100 800,600,500,500' result.png

There are basically 4 pairs of points in the parameters,i.e.

Pt1X,Pt1Y,Pt1NewX,Pt1NewY Pt2X,Pt2Y,Pt2NewX,Pt2NewY Pt3X,Pt3Y,Pt3NewX,Pt3NewY Pt4X,Pt4Y,Pt4NewX,Pt4NewY

So the command above moves point 0,0 to 50,0 and moves point 0,599 to 100,599 and so on.

I have labelled each of the points in red and drawn the path along which each one has moved in green.