1

画像の遠近法を設定します。空白のポリゴンを持つラップトップの画像がありますここに画像の説明を入力してください

別の画像を空白の領域にプルする必要があります。このような: ここに画像の説明を入力してください

だから、私は動的歪みのためにこのコードを持っています:

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

1 に答える 1

10

コントロールポイントは、必要な数の4のペアである必要がありますが、少なくとも3のペアである必要があります。コントロールポイントの意味は、source_x、source_y、destination_x、destination_yです。

つまり、基本的に、ソース画像のポイントが宛先画像のどこに配置されるべきかを示します。

あなたの場合、長方形の各コーナーに1つずつ、合計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>
);

明らかに、各宛先座標を把握し、上記の配列で置き換える必要があります。

于 2011-12-03T12:41:06.333 に答える