Drawing an Arc in Imagick

June 19, 2009

Image for Drawing an Arc in Imagick from unsplash.com

Here's how to draw an arc using PHP Imagick

$canvas = new Imagick();
$canvas->newImage(200, 200, new ImagickPixel("white"),'png');

$arc = new ImagickDraw();
$arc->setFillColor('red');
$arc->setStrokeColor('black');
$arc->setStrokeWidth(2);

/* x1,x2,y1,y2, start angle, end angle */
$arc->arc(30, 30, 160, 160, -70, 70);

$canvas->drawImage($arc);
$canvas->borderImage('black', 1, 1);
header('content-type: image/png');
echo $canvas->getImage();
exit();

Produces:

imagick_draw_arcphp