要填充弧线(DiameterX != DiameterY)
<?
function imagefilledarc($Image, $CenterX, $CenterY, $DiameterX, $DiameterY, $Start, $End, $Color) {
// 绘制弧线
imagearc($Image, $CenterX, $CenterY, $DiameterX, $DiameterY, $Start, $End, $Color);
// 用两条连接中心点和弧线两端的线来闭合弧线
$x = $CenterX + (cos(deg2rad($Start))*($DiameterX/2));
$y = $CenterY + (sin(deg2rad($Start))*($DiameterY/2));
imageline($Image, $x, $y, $CenterX, $CenterY, $Color);
$x = $CenterX + (cos(deg2rad($End))*($DiameterX/2));
$y = $CenterY + (sin(deg2rad($End))*($DiameterY/2));
imageline($Image, $x, $y, $CenterX, $CenterY, $Color);
// 要填充弧线,起始点是闭合空间中间的一个点
$x = $CenterX + (cos(deg2rad(($Start+$End)/2))*($DiameterX/4));
$y = $CenterY + (sin(deg2rad(($Start+$End)/2))*($DiameterY/4));
imagefilltoborder($Image, $x, $y, $Color, $Color);
}
?>
用两条线闭合弧线(DiameterX != DiameterY)
<?
function imagenofilledarc($Image, $CenterX, $CenterY, $DiameterX, $DiameterY, $Start, $End, $Color) {
// 绘制弧线
imagearc($Image, $CenterX, $CenterY, $DiameterX, $DiameterY, $Start, $End, $Color);
// 用两条连接中心点和弧线两端的线来闭合弧线
$x = $CenterX + (cos(deg2rad($Start))*($DiameterX/2));
$y = $CenterY + (sin(deg2rad($Start))*($DiameterY/2));
imageline($Image, $x, $y, $CenterX, $CenterY, $Color);
$x = $CenterX + (cos(deg2rad($End))*($DiameterX/2));
$y = $CenterY + (sin(deg2rad($End))*($DiameterY/2));
imageline($Image, $x, $y, $CenterX, $CenterY, $Color);
}
?>
一个例子
<?
$destImage = imagecreate( 216, 152 );
$c0 = imagecolorallocate( $destImage, 0, 255, 255 );
$c1 = imagecolorallocate( $destImage, 0, 0, 0 );
$c2 = imagecolorallocate( $destImage, 255, 0, 0 );
ImageFilledRectangle ( $destImage, 0, 0, 216, 152, $c0 );
imagefilledarc( $destImage, 108, 76, 180, 80, 0, 130, $c1 );
imagenofilledarc( $destImage, 108, 76, 180, 80, 0, 130, $c2 );
header("content-type: image/PNG");
ImagePNG( $destImage );
ImageDestroy( $destImage );
?>