Imagick PHP - Pie Slice?

Trying to create a ‘pie slice’ with the use of PHP’s Imagick/ImagickDraw classes.
So far I managed to draw the things I want… but I can’t figure out how to draw an arc. I did try use the ‘arc’ function, but it gives a different result from GD2’s arc so I asume I need to make use of another arc function.

Tried to use pathEllipticArcAbsolute, but it just gives me an error.

The only documentation available is:

bool ImagickDraw::pathEllipticArcAbsolute  ( float $rx  , float $ry  , float $x_axis_rotation  , bool $large_arc_flag  , bool $sweep_flag  , float $x  , float $y  )

Draws an elliptical arc from the current point to (x, y) using absolute coordinates. The size and orientation of the ellipse are defined by two radii (rx, ry) and an xAxisRotation, which indicates how the ellipse as a whole is rotated relative to the current coordinate system. The center (cx, cy) of the ellipse is calculated automatically to satisfy the constraints imposed by the other parameters. largeArcFlag and sweepFlag contribute to the automatic calculations and help determine how the arc is drawn. If largeArcFlag is TRUE then draw the larger of the available arcs. If sweepFlag is true, then draw the arc matching a clock-wise rotation.

  • sx
    Starting x ordinate of bounding rectangle
  • sy
    starting y ordinate of bounding rectangle
  • ex
    ending x ordinate of bounding rectangle
  • ey
    ending y ordinate of bounding rectangle
  • sd
    starting degrees of rotation
  • ed
    ending degrees of rotation

So I figured, since the parameter types are given I might as well give it a go and see what I end up with.


$width =  200;
$height = 100;

$img = new Imagick();
$img->newImage( $width, $height, new ImagickPixel( 'orange' ) );

$draw = new ImagickDraw();
$draw->setStrokeColor( new ImagickPixel( 'black' ) );
$draw->setStrokeWidth( 2 );
$draw->setFillColor( new ImagickPixel( 'lime' ) );
$draw->pathEllipticArcAbsolute( $width/2, $height/2, 0, true, false, 0, 30  );
$img->drawImage( $draw );
$img->setImageFormat( "png" );

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

Which throws the following error:

Fatal error: Uncaught exception ‘ImagickException’ with message ‘Non-conforming drawing primitive definition `A100’’ in /srv/www/htdocs/fetish/index.php:556 Stack trace: #0 /srv/www/htdocs/fetish/index.php(556): Imagick->drawimage(Object(ImagickDraw)) #1 {main} thrown in /srv/www/htdocs/fetish/index.php on line 556

So… anyone know how to draw an arc?
To confirm everything aside the arc is working comment out $draw->pathEllipticArcAbsolute and it will draw an orange rectangle.