Question

Is there a way to get GD's function imagefilledarc()'s result in using PHP ImageMagick? I've looked around but haven't found a satisfying solution so far. I want it to support transparency, and use it to draw pies.

Was it helpful?

Solution 4

Since this post gets hit by googlers every now and then, and doesn't have a valid answer, I figured I should give some hints. There is an excellent library called Imagine (https://github.com/avalanche123/Imagine) which supports the most popular PHP image libraries (ImageMagick, GraphicsMagick and GD) using the same calls.

It's API includes a pieSlice function (https://imagine.readthedocs.io/en/stable/_static/API/Imagine/Draw/DrawerInterface.html#method_pieSlice). The source for that function is https://github.com/avalanche123/Imagine/blob/develop/src/Imagick/Drawer.php#L242

OTHER TIPS

Your best bet would be to use ImageMagick::Draw. It has an arc command; instead of specifying the center, you specify the bounding rectangle. You just need to add a command before it to set the fill, and perhaps after it to close the fill.

http://us.php.net/manual/en/function.imagickdraw-arc.php

As far as I know ImagickDraw::arc is the only way to do it (unless you want to create a function that draws it pixel by pixel). But to get it working the same way as gd, you just have to make minor changes. For instance, this:

imagearc($image, $cx, $cy, $width, $height, $start, $end, $color);

Should be equivalent to this (I haven't tested it):

ImagickDraw::setStrokeColor($imageMagickColor);    //I don't remember how to allocate the color
ImagickDraw::arc($cx-$width/2, $cy-$height/2, $cx+$width/2, $cy+$height/2, $start, $end);

Not exactly what you were asking, but it's easy to draw pie charts with Google Chart API http://code.google.com/apis/chart/

alt text

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top