MD Sayem Ahmed
MD Sayem Ahmed

Reputation: 29166

How to draw this type of image in PHP

I want to draw an image in PHP, which looks like the circle in the following image -


How should I proceed with this? Is there any available PHP plugin or something that I can use to generate this type of image, or should I use GD library and hand-code it myself?

EDIT I am looking for some library that is open-source.

Upvotes: 1

Views: 824

Answers (6)

Mark Lalor
Mark Lalor

Reputation: 7887

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:

Image does not exist

Upvotes: 2

Mark Lalor
Mark Lalor

Reputation: 7887

imagefilledarc is your friend!

Upvotes: 1

gclj5
gclj5

Reputation: 1956

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.

Upvotes: 2

ebt
ebt

Reputation: 1358

your probably looking for an SVG library.

raphael is also a good choice

Upvotes: 1

2ndkauboy
2ndkauboy

Reputation: 9377

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:

  1. JpGraph
  2. GraPHPite
  3. Google Chart Tools

Have a look at what they offer you. Might not be the exact same but something very close.

Upvotes: 6

Select0r
Select0r

Reputation: 12628

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/

Upvotes: 4

Related Questions