2011-04-19 80 views
1

我要設置圖像的角度。我有空白多邊形筆記本電腦的圖像enter image description hereimagick :: distortimage

需要在空白區域拉另一個圖像。就像這樣: enter image description here

所以,我對動態失真驗證碼:

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

如何設置$控制點陣列?我不能只設置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); 

回答

8

控制點應該是對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> 
); 

很明顯,你必須要弄清楚每個目標的座標及以上陣列中更換。