I want to draw an image in PHP, which looks like th开发者_开发百科e circle in the following image -
EDIT I am looking for some library that is open-source.
Do not handcode it yourself as that would be very painful. I once had to code a pie-chart generator.
There are plenty of graph engines out there:
- JpGraph
- GraPHPite
- Google Chart Tools
Have a look at what they offer you. Might not be the exact same but something very close.
I don't know what you're trying to display in that image but it looks like some kind of graph, so I'd look for a chart-library, e.g. JpGraph, before coding it all again:
http://jpgraph.net/
This looks like a bar chart converted to polar coordinates.
Here's an easy way to generate such a picture:
Draw your bars (either using a chart library or on your own) without any gaps between the bars. Make sure there is no whitespace to the left and right of your bars.
Transform the image to polar coordinates using GD's
gdImageSquareToCircle()
function
You probably might have to rotate your bars by 180° (i.e. the bars should grow from top to bottom) before transforming the image.
This:
$im = imagecreatetruecolor(500, 500);
imagefill($im, 0, 0, imagecolorallocate($im, 255, 255, 255));
imagefilledarc($im, 250, 250, 500, 500, -90, -80, 0xFF0000, IMG_ARC_PIE);
imagefilledarc($im, 250, 250, 400, 400, -80, -40, 0xFFFF00, IMG_ARC_PIE);
imagefilledarc($im, 250, 250, 150, 150, -40, 0, 0xFF00FF, IMG_ARC_PIE);
imagefilledarc($im, 250, 250, 450, 450, 0, 20, 0x00FFFF, IMG_ARC_PIE);
imagefilledarc($im, 250, 250, 350, 350, 20, 50, 0x1276A9, IMG_ARC_PIE);
imagefilledarc($im, 250, 250, 100, 100, 50, 95, 0x000000, IMG_ARC_PIE);
imagefilledarc($im, 250, 250, 400, 400, 95, 125, 0x1E1FFF, IMG_ARC_PIE);
imagefilledarc($im, 250, 250, 150, 150, 125, 160, 0x45ABAB, IMG_ARC_PIE);
imagefilledarc($im, 250, 250, 500, 500, 160, 180, 0xFFA7F1, IMG_ARC_PIE);
imagefilledarc($im, 250, 250, 300, 300, 180, 235, 0xA91234, IMG_ARC_PIE);
imagefilledarc($im, 250, 250, 240, 240, 235, 255, 0xA13ACE, IMG_ARC_PIE);
imagefilledarc($im, 250, 250, 300, 300, 255, 270, 0x00FF00, IMG_ARC_PIE);
header("Content-type: image/png");
imagepng($im);
Makes this:
your probably looking for an SVG library.
raphael is also a good choice
imagefilledarc
is your friend!
精彩评论