Ale*_*kin 1 php imagick distortion perspective
我要设置图像透视图.我有空白多边形的笔记本电脑的形象
需要在空白区域上拉出另一张图像.像这样:

所以,我有动态失真的代码:
$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);
Run Code Online (Sandbox Code Playgroud)
如何设置$ controlPoints数组?我不能只为图像的每个角设置4个坐标?不幸的是,imageick :: distort图像的文档很差.
通过使用另一种失真方法解决问题:
$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);
Run Code Online (Sandbox Code Playgroud)
Dan*_*gea 10
控制点应该是4对,尽可能多,但至少3对.控制点的含义是source_x,source_y,destination_x,destination_y
所以它基本上告诉源图像中的点应该在目标图像中的哪个位置.
在您的情况下,您将需要4对,矩形的每个角落一个:
$controlPoints = array(
0, 0, <destination_x>, <destination_y>,
0, $im->getImageHeight(), <destination_x>, <destination_y>,
$im->getImageWidth(), 0, <destination_x>, <destination_y>,
$im->getImageWidth(), $im->getImageHeight(), <destination_x>, <destination_y>
);
Run Code Online (Sandbox Code Playgroud)
显然,您必须弄清楚每个目标坐标并替换上面的数组.