11-05-2007, 01:23 PM
I need to create a circle in php with specified width and height. Can it be done using the createimage for gif and png formats.
Also i like to have some ideas on venn diagrams using php.
Hi there, the following code should give you the circle that you require. I've not tested the code so not sure if it works! I just bashed it out quickly. Check out the image<whatever> functions at www.php.net to understand what they do.
$diameter = $_REQUEST["diameter"];
if ($im = imagecreate($diameter, $diameter))
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefill($im, 0, 0, $white);
imagearc($im, $diameter/2, $diameter/2, $diameter, $diameter, 0, 360, $black);
header("content-type:image/png"); //This tells the web browser to expect a PNG image.
else echo "whoops!";
if you put that code as it is into a file called "circle.php" on your webserver then you can generate cirles of whatever diameter you want by adjusting the diameter get var.
For example: http:// ... /circle.php?diameter=101 will give you a 101x101 pixel circle (don't use an even number for a diameter or else you'll loose the rightmost and bottom-most pixels).
Note that I've only coded for the single argument "diameter" rather than for separate width and height because a circle with width not equal to height is not a circle ... ;)
I hope that helps and I hope the code works! (as I said, I;ve not tested the code, so there may be the odd bug in it!). If it works for you, you can easily modify that code to make venn diagrams (just move the locus of each circle that you draw).
Note that you need the GD2 library included in your PHP build for many of the image functions to work.
11-05-2007, 02:02 PM
A lot of information on GD graphs and charts:
Not so much about Venn diagrams, but perhaps someone has an example?
11-06-2007, 04:39 AM
Thanks for your answers. Im just going through it and let me get back with the best code out of it.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.