如何使用 PHP 中的 imagefilledarc() 函数绘制部分圆弧并填充?
phpserver side programmingprogramming
imagefilledarc() 是 PHP 中的内置函数,用于绘制部分圆弧并填充。
语法
bool imagefilledarc($image, $cx, $cy, $width, $height, $start, $end, $color, $style)
参数
imagefilledarc() 有九个参数:$image, $cx, $cy, $width、$height、$start、$end、$color 和 $style。
$image − 由图像创建函数 imagecreatetruecolor() 返回。此函数用于创建图像的大小。
$cx − 设置中心的 x 坐标。
$cy − 设置中心的 y 坐标。
$width −设置弧宽。
$height − 设置弧高。
$start − 起始角度,单位为度。
$end − 弧结束角度,单位为度。00 位于三点钟位置,弧按顺时针方向绘制。
$color − 使用 imagecolorallocate() 函数创建的颜色标识符。
$style −建议如何填充图像,其值可以是以下列表中的任何一个 −
IMG_ARC_PIE
IMG_ARC_CHORD
IMG_ARC_NOFILL
IMG_ARC_EDGED
IMG_ARC_PIE 和 IMG_ARC_CHORD 都是互斥的。
IMG_ARC_CHORD 从起始角和终止角连接一条直线,而 IMG_ARC_PIE 产生圆边。
IMG_ARC_NOFILL 表示应该勾勒出弧线或弦线的轮廓,而不是填充。
IMG_ARC_EDGED与IMG_ARC_NOFILL一起使用,表示起始角和终止角应连接到中心。
返回值
成功时返回True,失败时返回False。
示例1
<?php define("WIDTH", 700); define("HEIGHT", 550); // 创建图像。 $image = imagecreate(WIDTH, HEIGHT); // 分配颜色。 $bg = $white = imagecolorallocate($image, 0x00, 0x00, 0x80); $gray = imagecolorallocate($image, 122, 122, 122); // 制作饼形弧。 $center_x = (int)WIDTH/2; $center_y = (int)HEIGHT/2; imagerectangle($image, 0, 0, WIDTH-2, HEIGHT-2, $gray); imagefilledarc($image, $center_x, $center_y, WIDTH/2, HEIGHT/2, 0, 220, $gray, IMG_ARC_PIE); // 刷新图像。 header("Content-Type: image/gif"); imagepng($image); ?>
输出
示例 2
<?php // 使用 imagecreatetruecolor 函数创建图像。 $image = imagecreatetruecolor(700, 300); // 分配 darkgray 和 darkred 颜色 $darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90); $darkred = imagecolorallocate($image, 0x90, 0x00, 0x00); // 制作 3D 效果 for ($i = 60; $i > 50; $i--) { imagefilledarc($image, 100, $i, 200, 100, 75, 360, $darkred, IMG_ARC_PIE); } imagefilledarc($image, 100, $i, 200, 100, 45, 75 , $darkgray, IMG_ARC_PIE); // 刷新图像 header('Content-type: image/gif'); imagepng($image); imagedestroy($image); ?>