PHP | imagickdraw affine()函数
ImagickDraw::affine()函数是PHP中的一个内置函数,用于调整当前的仿射变换矩阵。
句法:
bool ImagickDraw::affine( array $affine )
参数:此函数接受单个参数$affine ,其中包含包含仿射矩阵参数的数组。
返回值:此函数在成功时返回 TRUE。
异常:此函数在出错时抛出 ImagickException。
下面给出的程序说明了PHP中的ImagickDraw::affine()函数:
方案一:
newImage(800, 250, 'green');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
// Translate the object
$draw->translate(100, 100);
// Apply the affine() function
$draw->affine(array("sx" => 7, "sy" => 1,
"rx" => 9, "ry" => 0,
"tx" => 200, "ty" => 0));
// Draw a rectangle
$draw->rectangle(-50, -50, 50, 50);
// Render the draw commands in the ImagickDraw object
$imagick->drawImage($draw);
// Show the output
$imagick->setImageFormat("png");
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
输出:
方案二:
newImage(800, 250, 'purple');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
// Translate the object
$draw->translate(100, 100);
// Apply the affine() function
$draw->affine(array("sx" => 2, "sy" => 1,
"rx" => 0, "ry" => 0,
"tx" => 0, "ty" => 0));
// Draw a rectangle
$draw->rectangle(0, -50, 50, 50);
// Draw a rectangle
$draw->rectangle(100, 50, 150, 100);
// Draw a rectangle
$draw->rectangle(200, -10, 250, 90);
// Render the draw commands in the ImagickDraw object
$imagick->drawImage($draw);
// Show the output
$imagick->setImageFormat("png");
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
输出:
参考: https://www. PHP.net/manual/en/imagickdraw.affine。 PHP