PHP 中的 imagearc() 函数
phpserver side programmingprogramming更新于 2025/7/6 7:52:17
imagearc() 函数用于绘制圆弧。
语法
imagearc( $img, $cx, $cy, $width, $height, $start, $end, $color )
参数
$img:使用 imagecreatetruecolor() 创建图像。
$cx:圆心 x 坐标。
$cy:圆心 y 坐标。
$width:圆弧的宽度。
$height:圆弧的高度圆弧。
$start:圆弧起始角度,以度为单位。
$end:圆弧结束角度,以度为单位。
$color:设置图像颜色。
返回
imagearc() 函数成功时返回 TRUE,失败时返回 FALSE。
示例
以下是示例:
<?php
$img = imagecreatetruecolor(200, 200);
$one = imagecolorallocate($img, 100, 50, 255);
$two = imagecolorallocate($img, 30, 255, 150);
imagearc($img, 100, 100, 200, 200, 0, 360, $one);
imagearc($img, 130, 50, 100, 150, 25, 155, $two);
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
?>
输出
输出结果如下:

示例
让我们看另一个例子,其中我们有不同的坐标和弧角:
<?php
$img = imagecreatetruecolor(250, 250);
$one = imagecolorallocate($img, 100, 90, 255);
$two = imagecolorallocate($img, 100, 255, 190);
imagearc($img, 130, 100, 200, 200, 0, 360, $one);
imagearc($img, 140, 50, 140, 150, 95, 155, $two);
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
?>
输出
输出结果如下:

