ImageMagick & Pie Charts

2019-07-31 19:19发布

问题:

What is the most direct way to draw a pie chart using ImageMagick in an existing image. For example, how would I draw a single slice given the following inputs?

  • A center point (x,y)
  • Radius
  • Percent

回答1:

Create your pie wedge using SVG; I got my example from here:

<svg>
<path d="M200,200 L200,20 A180,180 0 0,1 377,231 z"
    style="fill:#ff0000;
        fill-opacity: 1;
        stroke:black;
        stroke-width: 1"/>
</svg>

Then, overlay that image using ImageMagick to your background image.

composite.exe -background none -size 200x200 .\pie_wedge.svg .\background.png out.png

Note that you have to define your arcs with cartesian coordinates instead of radius, but the conversion should be fairly straightforward.