imagick::扭曲图像

发布于 2024-11-01 21:04:01 字数 1349 浏览 5 评论 0原文

我要设置图像透视。我有带有空白多边形的笔记本电脑的图像 在此处输入图像描述

需要在空白区域上拉动另一个图像。像这样: 在此处输入图像描述

因此,我有以下用于动态失真的代码:

$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 enter image description here

Another image needs to be pulled on a blank area. Like this:
enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱人如己 2024-11-08 21:04:01

控制点应为 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>
);

显然,您必须找出每个目标坐标并替换到上面的数组中。

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:

$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>
);

Obviously, you will have to figure out each destination coordinate and replace in the array above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文