PHP | imagickdraw setFillPatternURL()函数
ImagickDraw::setFillPatternURL()函数是PHP中的一个内置函数,用于设置 URL 以用作填充对象的填充模式。 URL 实际上是模式的唯一名称,名称前带有“#”。
句法:
bool ImagickDraw::setFillPatternURL( string $fill_url )
参数:此函数接受一个包含 URL 的参数$fill_url 。
返回值:此函数在成功时返回 TRUE。
下面的程序说明了PHP中的ImagickDraw::setFillPatternURL()函数:
方案一:
newImage(800, 250, 'black');
// Create a new imagickDraw object
$draw = new ImagickDraw();
// Push the pattern
$draw->pushPattern("MyPattern", 0, 0, 50, 50);
$color = ['blue', 'black', 'cyan'];
for ($x = 0; $x < 50; $x += 10) {
for ($y = 0; $y < 50; $y += 5) {
$draw->setFillColor($color[$y % 3]);
$draw->circle($x, $y + 80, $x % 2, $y);
}
}
// Pop the pattern
$draw->popPattern();
// Set the fill Opacity
$draw->setFillOpacity(0);
// Set the fill pattern URL
$draw->setFillPatternURL('#MyPattern');
// Draw a rectangle on which pattern is made
$draw->rectangle(0, 0, 400, 400);
// Render the draw commands
$imagick->drawImage($draw);
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
输出:
方案二:
newImage(800, 250, 'white');
// Create a new imagickDraw object
$draw = new ImagickDraw();
// Push the pattern
$draw->pushPattern("MyPattern", 0, 0, 50, 50);
for ($x = 0; $x < 50; $x += 10) {
for ($y = 0; $y < 50; $y += 5) {
$draw->rectangle($x, $y + 80, $x % 2, $y);
}
}
// Pop the pattern
$draw->popPattern();
// Set the fill Opacity
$draw->setFillOpacity(0);
// Set the fill pattern URL
$draw->setFillPatternURL('#MyPattern');
// Draw a rectangle on which pattern is made
$draw->rectangle(0, 0, 900, 900);
// Render the draw commands
$imagick->drawImage($draw);
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
输出:
参考: https://www. PHP.net/manual/en/imagickdraw.setfillpatternurl。 PHP