imagick::扭曲图像
我要设置图像透视。我有带有空白多边形的笔记本电脑的图像
需要在空白区域上拉动另一个图像。像这样:
因此,我有以下用于动态失真的代码:
$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);
如何设置 $controlPoints 数组?我不能只为图像的每个角设置 4 个坐标吗?不幸的是,imageick::扭曲图像的文档很差。
使用另一种扭曲方法解决了问题:
$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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
控制点应为 4 对,根据需要任意数量,但至少 3 对。
控制点的含义是
source_x、source_y、destination_x、destination_y
所以它基本上告诉源图像中的点应该在目标图像中的位置。
在您的情况下,您将需要 4 对,矩形的每个角各一对:
显然,您必须找出每个目标坐标并替换到上面的数组中。
The control points should be pairs of 4, as many as you need but at least 3 pairs.
The meaning of control points is
source_x, source_y, destination_x, destination_y
So it basically tells where should points from the source image go in the destination image.
In your case you will need 4 pairs, one for each corner of the rectangle:
Obviously, you will have to figure out each destination coordinate and replace in the array above.