希望这对您有所帮助,我花了很长时间才绘制出一个简单的饼图切片,在 GD2 中使用 'arc' 函数很容易完成.. 在 imagick 中做起来有点难。
角度很混乱,路径、弧线和椭圆函数似乎都使用不同的系统.. 非常令人困惑。
下面的代码至少可以帮助您理解它的工作原理。
有关输出示例,请参见
http://www.imagebam.com/image/8e0ca432393602
<?php
function getPointOnCircumference( $widthOfCircle, $heightOfCircle, $degrees, $x = 0, $y = 0 )
{
return array(
'x' => $x + ($widthOfCircle/2) * sin( deg2rad( $degrees ) ),
'y' => $y + ($heightOfCircle/2) * cos( deg2rad( $degrees ) )
);
}
$width = 200;
$height = 200;
$border = 2;
$x = $width / 2;
$y = $height / 2;
$im = new Imagick();
$im->newImage( $width, $height, "orange", "png" );
$draw = new ImagickDraw();
$draw->setFillColor( 'lime' );
$draw->setStrokeColor( new ImagickPixel( 'black' ) );
$draw->setStrokeWidth( 2 );
$draw->arc( 0, 0, ($width-$border), ($height-$border), 270, 360 ); // 270 到 360 度
$im->DrawImage( $draw );
$draw2 = new ImagickDraw();
$draw2->setFillColor( 'red' );
$draw2->setStrokeColor( new ImagickPixel( 'black' ) );
$draw2->setStrokeWidth( 2 );
$draw2->ellipse( 100, 100, $x-$border, $y-$border, 0, 90 ); // 0 到 90 度
$im->DrawImage( $draw2 );
$draw3 = new ImagickDraw();
$draw3->setFillColor( 'navy' );
$draw3->setStrokeColor( new ImagickPixel( 'white' ) );
$draw3->setStrokeWidth( 2 );
$draw3->pathStart();
$degrees90 = getPointOnCircumference( $width-2*$border,$height-2*$border, 360 );
$degrees180 = getPointOnCircumference( $width-2*$border,$height-2*$border, 270 );
$draw3->pathMoveToRelative( $x, $y ); // 将“铅笔”移动到图像中间。
$draw3->pathLineToRelative( $degrees90['x'], $degrees90['y'] );
$draw3->pathEllipticArcRelative( $width-$border, $height-$border, 0, false, true, $degrees180['x'], $degrees180['y']-$y+$border );
$draw3->pathClose();
$im->DrawImage( $draw3 );
header( "Content-Type: image/png" );
echo $im;
?>