douju9272 2011-04-19 03:12
浏览 39
已采纳

imagick :: distortimage

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);
  • 写回答

1条回答 默认 最新

  • duanqin7791 2011-12-03 12:41
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配