1

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.

enter image description here

enter image description here

1
  • What have you done so far?
    – Observer
    May 3, 2018 at 17:31

1 Answer 1

1

Using this 800x600 balloon:

enter image description here

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.

enter image description here

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

5
  • how you calculated 4 xy coordinates values to place image. Can you please explain this command. I want to know how I will put image on my 2nd example.
    – Sumeet Roy
    May 9, 2018 at 11:25
  • I'm not sure what you don't understand - I have added a red border now so you can see the extent of the image. The top-left corner (0,0) has moved 20 pixels to the right and is now at (20,0). May 9, 2018 at 13:58
  • It would be helpful to explain if you provide two separate images --- the input and the desired output. The coordinates are not computed. They are measure in the input image and usually in the output image from the corners or the image or some object within the image. That makes 4 x,y pairs for the input and 4 x,y pairs for the output. The order is inx1,iny1 outx1,outy1 ... inx4,iny4 outx4,outy4. If you do not have an output to measure, you can do perspective transformation via rotation angle. See my script 3Drotate at fmwconcepts.com/imagemagick/index.php
    – fmw42
    May 9, 2018 at 16:46
  • Thanks to both of you for giving valuable time. Please check the new example I added.
    – Sumeet Roy
    May 10, 2018 at 8:23
  • See duplicates question and solution at stackoverflow.com/questions/50491068/…
    – fmw42
    May 26, 2018 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.