Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: circle in php

  1. #1
    New Coder
    Join Date
    Apr 2007
    Location
    India
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    circle in php

    Hi,

    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.
    GemGuy

    Be friend of me
    Hey what a fun

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    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.

    PHP Code:
    <?php
    $diameter 
    $_REQUEST["diameter"];

    if (
    $im imagecreate($diameter$diameter))
    {  
      
    $white imagecolorallocate($im255255255);
      
    $black imagecolorallocate($im000);

      
    imagefill($im00$white);

      
    imagearc($im$diameter/2$diameter/2$diameter$diameter0360$black);

      
    header("content-type:image/png");  //This tells the web browser to expect a PNG image.
      
    imagepng($im);
      
      
    imagecolordeallocate($im$white);
      
    imagecolordeallocate($im$black);
      
    imagedestroy($im);
    }
    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.

    Regards,

    Mike.
    Last edited by mlse; 11-05-2007 at 03:19 PM.

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    A lot of information on GD graphs and charts:
    http://www.google.com/search?hl=en&s...hs&btnG=Search

    Not so much about Venn diagrams, but perhaps someone has an example?

  • #4
    New Coder
    Join Date
    Apr 2007
    Location
    India
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    circle using imagecreate

    Hi mlse,mlseim,

    Thanks for your answers. Im just going through it and let me get back with the best code out of it.
    GemGuy

    Be friend of me
    Hey what a fun


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •