PHP | imagickdraw polyline()函数
ImagickDraw::polyline()函数是PHP的 Imagick 库中的一个内置函数,用于使用指定的坐标数组使用当前笔画、笔画宽度和填充颜色或纹理绘制折线。
句法:
bool ImagickDraw::polyline( $coordinates )
参数:此函数接受单个参数$coordinates ,该参数用于将点的坐标保存为数组。
返回值:此函数在成功时返回 True。
下面的程序说明了PHP中的ImagickDraw::polyline()函数:
方案一:
setStrokeOpacity(1);
// Set Stroke Color
$draw->setStrokeColor('green');
// Set Fill Color
$draw->setFillColor('red');
// Set Stroke Width
$draw->setStrokeWidth(5);
// Define the points at which lines to be draw
$points = [
['x' => 40 * 5, 'y' => 10 * 5],
['x' => 20 * 5, 'y' => 20 * 5],
['x' => 70 * 5, 'y' => 50 * 5],
['x' => 60 * 5, 'y' => 15 * 5]
];
// Call Polyline Function
$draw->polyline($points);
// Create an Imagick Object
$image = new Imagick();
// Create new Image
$image->newImage(500, 300, 'white');
// Set Image Format
$image->setImageFormat("png");
// Draw Image
$image->drawImage($draw);
header("Content-Type: image/png");
// Display the output image
echo $image->getImageBlob();
?>
输出:
方案二:
setStrokeOpacity(1);
// Set Stroke Color
$draw->setStrokeColor('Black');
// Set Fill Color
$draw->setFillColor('Green');
// Set Stroke Width
$draw->setStrokeWidth(3);
// Define the points at which lines to be draw
$points = [
['x' => 40 * 5, 'y' => 10 * 5],
['x' => 20 * 5, 'y' => 20 * 5],
['x' => 70 * 5, 'y' => 50 * 5],
['x' => 40 * 5, 'y' => 10 * 5]
];
// Set the Font Size
$draw->setFontSize(50);
// Set the font family
$draw->setFontFamily('Ubuntu-Mono');
// Set the text to be added
$draw->annotation(30, 40, "GeeksForGeeks");
// Call Polyline Function
$draw->polyline($points);
// Create an Imagick Object
$image = new Imagick();
// Create new Image
$image->newImage(500, 300, 'white');
// Set Image Format
$image->setImageFormat("png");
// Draw Image
$image->drawImage($draw);
header("Content-Type: image/png");
// Display the output image
echo $image->getImageBlob();
?>
输出:
参考: http: PHP。 PHP
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。