0

What I am trying to achieve is exactly the person in this question is trying. But in my case I want to code it as a PHP script.

I have seen some code to do it like this:

$controlPoints = array(
    10, 10,
    10, 5,

    10, $screenshot->getImageHeight() - 20,
    10, $screenshot->getImageHeight() - 5,

    $screenshot->getImageWidth() - 10, 10,
    $screenshot->getImageWidth() - 10, 20,

    $screenshot->getImageWidth() - 10, $screenshot->getImageHeight() - 10,
    $screenshot->getImageWidth() - 10, $screenshot->getImageHeight() - 30);


$screenshot->distortImage(Imagick::DISTORTION_PERSPECTIVE, $controlPoints, true);

But unfortunately I don't understand the maths behind the control points.

I think if I only had to input the 4 coordinates of the Image where I want to "stretch" the image it would be exactly what I need, but I'm not sure how to do it.

Community
  • 1
  • 1
Enrique Moreno Tent
  • 24,127
  • 34
  • 104
  • 189

1 Answers1

0

The control points are coordinates identifying which pixels to move and to where. For example, if the first two numbers are 0, 0 they identify the pixel in the top,left corner. The next pair of numbers indicate the destination of that first pixel after the distortion. The next pair identify the second pixel to move, followed by the coordinates of its destination. You provide the coordinates for four locations (corners, for example) and the software figures out what to do with all the pixels in between.

Your four pairs of coordinates are four corners of a box: where they are and where you want them to be.

There are some good examples on the ImageMagick Usage site.

T-Dor
  • 536
  • 3
  • 7