to keep it simple I am trying to put a image on a image/canvas.
Canvas = 1920×1080, image size doesn’t matter.
I want to add the image into the canvas but with specific x/y coordination for each corner.
Look at my array here below to see what I’m working with:
[0] => Array
(
[cp1x] => 500
[cp1y] => 250
[cp2x] => 250
[cp2y] => 380
[cp3x] => 400
[cp3y] => 700
[cp4x] => 1500
[cp4y] => 800
)
CP1X/CP1Y are for the top left.
CP2X/CP2Y are for the top right.
CP3X/CP3Y are for the lower left.
CP4X/CP4Y are for the lower right.
I’d preferably get a solution in php and -or ImageMagick.
Also made sketches to give a better explanation.
Hope it’s all clear.
Tried making it with Imagick and PHP transform.
2
Answers
I don’t have any working PHP setup, but here’s how you do it on the command line. I used a 1920×1080 swirl as the background (
bg.jpg
) with your 400×400 overlay image as the foreground (fg.jpg
) to distort:You will see there are 4 pairs of coordinates, with those in the source image listed before the corresponding point in the destination image.
Your coordinates do not match your description. They are list counter clockwise from the top left.
You can get the result in Imagemagick using +distort perspective between your coordinates and the corners of the input images.
Input:
Unix syntax:
Result: