I'm going to set image perspective. I have image of laptop with blank polygon
Another image needs to be pulled on a blank area. Like this:
So, I have this code for dynamical distortion:
$controlPoints = array( 0, 0,
0, 0,
0, $im->getImageHeight(),
0, $im->getImageHeight(),
$im->getImageWidth(), 0,
$im->getImageWidth(), 0,
$im->getImageWidth(), $im->getImageHeight(),
$im->getImageWidth(), $im->getImageHeight());
/* Perform the distortion */
$im->distortImage(Imagick::DISTORTION_PERSPECTIVE, $controlPoints, true);
How can I set $controlPoints array? I can't just set 4 coordinates to each corner of image? Unfortunately, documention for imageick::distort image is poor.
Problem is solved by using another distortion method:
$im->cropImage( 125, 121, $center_x, $center_y );
$controlPoints = array(
0,0, 35,20, # top left
190,0, 150,30, # top right
0,205, -16,105, # bottom right
176,135, 115,105 # bottum left
);
/* Perform the distortion */
$im->distortImage(Imagick::DISTORTION_BILINEAR, $controlPoints, true);