PHP Conference Japan 2024

ImagickDraw::affine

(PECL imagick 2, PECL imagick 3)

ImagickDraw::affine調整目前的仿射變換矩陣

說明

public ImagickDraw::affine(array $affine): bool
警告

此函式目前沒有文件;只有它的參數列表可用。

使用指定的仿射變換矩陣調整目前的仿射變換矩陣。

參數

affine

仿射矩陣參數

傳回值

不傳回任何值。

範例

範例 #1 ImagickDraw::affine() 範例

<?php
function affine($strokeColor, $fillColor, $backgroundColor) {

$draw = new \ImagickDraw();

$draw->setStrokeWidth(1);
$draw->setStrokeOpacity(1);
$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);

$draw->setStrokeWidth(2);

$PI = 3.141592653589794;
$angle = 60 * $PI / 360;

//縮放繪圖座標。
$affineScale = array("sx" => 1.75, "sy" => 1.75, "rx" => 0, "ry" => 0, "tx" => 0, "ty" => 0);

//剪切繪圖座標。
$affineShear = array("sx" => 1, "sy" => 1, "rx" => sin($angle), "ry" => -sin($angle), "tx" => 0, "ty" => 0);

//旋轉繪圖座標。剪切仿射矩陣
//會產生錯誤縮放的繪圖。
$affineRotate = array("sx" => cos($angle), "sy" => cos($angle), "rx" => sin($angle), "ry" => -sin($angle), "tx" => 0, "ty" => 0,);

//平移(偏移)繪圖。
$affineTranslate = array("sx" => 1, "sy" => 1, "rx" => 0, "ry" => 0, "tx" => 30, "ty" => 30);

//單位仿射矩陣。
$affineIdentity = array("sx" => 1, "sy" => 1, "rx" => 0, "ry" => 0, "tx" => 0, "ty" => 0);

$examples = [$affineScale, $affineShear, $affineRotate, $affineTranslate, $affineIdentity,];

$count = 0;

foreach (
$examples as $example) {
$draw->push();
$draw->translate(($count % 2) * 250, intval($count / 2) * 250);
$draw->translate(100, 100);
$draw->affine($example);
$draw->rectangle(-50, -50, 50, 50);
$draw->pop();
$count++;
}

//建立一個影像物件,可以將繪圖指令渲染到其中
$image = new \Imagick();
$image->newImage(500, 750, $backgroundColor);
$image->setImageFormat("png");

//將 ImagickDraw 物件中的繪圖指令渲染到影像中。
$image->drawImage($draw);

//將影像傳送到瀏覽器
header("Content-Type: image/png");
echo
$image->getImageBlob();
}

?>

新增註解

使用者貢獻的註解

此頁面沒有使用者貢獻的註解。
To Top