(PECL imagick 2, PECL imagick 3)
ImagickDraw::affine — 调整当前仿射变换矩阵
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();
}
?>