php imagepolygon,PHP GmagickDraw polygon()用法及代码示例

GmagickDraw::polygon()函数是PHP中的一个内置函数,用于使用指定的坐标数组使用当前笔触,笔触宽度以及填充颜色或纹理绘制多边形。

用法:

GmagickDraw GmagickDraw::polygon( array $coordinates )

参数:该函数接受单个参数$coordinates,该参数保存坐标数组。

返回值:成功时,此函数返回GmagickDraw对象。

异常:该函数在错误时引发GmagickDrawException。

使用的图片:

228c98d6ff62e907625fff7fe242f4b7.png

以下示例说明了PHP中的GmagickDraw::polygon()函数:

范例1:绘制图像。

// Create a new Gmagick object

$gmagick = new Gmagick('geeksforgeeks.png');

// Create a GmagickDraw object

$draw = new GmagickDraw();

// Set the fill color

$draw->setFillColor('red');

// Set the stroke color

$draw->setstrokecolor('green');

// Set the stroke width

$draw->setStrokeWidth(5);

// Create a polygon

$draw->polygon([

['x' => 300, 'y' => 50],

['x' => 140, 'y' => 150],

['x' => 380, 'y' => 150],

['x' => 110, 'y' => 75],

]);

// Use of drawimage function

$gmagick->drawImage($draw);

// Display the output image

header("Content-Type:image/png");

echo $gmagick->getImageBlob();

?>

输出:

c624e0eb79b117ebbe8aaabf7d5c24ab.png

范例2:从头开始绘制。

// Create a new Gmagick object

$gmagick = new Gmagick('geeksforgeeks.png');

// Create a GmagickDraw object

$draw = new GmagickDraw();

// Draw rectangle for background

$draw->rectangle(-10, -10, 800, 400);

// Set the fill color

$draw->setFillColor('#0E0E0E');

// Set the stroke color

$draw->setstrokecolor('green');

// Set the stroke width

$draw->setStrokeWidth(5);

// Create a polygon

$draw->polygon([

['x' => 400, 'y' => 50],

['x' => 40, 'y' => 150],

['x' => 480, 'y' => 150],

['x' => 110, 'y' => 75],

]);

// Use of drawimage function

$gmagick->drawImage($draw);

// Display the output image

header("Content-Type:image/png");

echo $gmagick->getImageBlob();

?>

输出:

5fa53618fc79f10af68191ae269fa565.png


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部