RJP63

Navigation

  • Home
  • Wall Papers
  • Photos
  • Games
  • Utilities
  • Running Routes

PHP

  • Syntax Highlighter
  • Antialiased Ellipse

Files

  • File Store

Web Cam

  • Web Cam

Stats

  • Public

Antialiased, Filled Ellipse In PHP

Introduction

Basically I had been messing about doing some programming in PHP and tried some image manipulation. Whilst most of the stuff is there from GD it appears that the antialias functions don't work for most of the curved functions (i.e. imagefilledellipse() and others) as a result you can output a really nice graphic, so long as you use straight lines every where, not very exciting I am sure you will agree!

As result of a bit of research and a lot of copying other contributed code I have cobbled together some code to draw antialiased, filled ellipses. Now I am just a hobbiest when it comes to programming so I apologise in advance for the state of the code but it works so hopefully it will help someone.

The Code

For the source click here.

Included in the file are four functions, these are:-

  • color2rgb($color) - converts a GD color value created using imagecolorallocate() etc. to an rgb array so that the individual values can be accessed.

  • color2rgba($color) - does the same as color2rgb() except for a color value with an alpha value too.

  • imagefilledellipseaa_Plot4EllipsePoints(&$im, $CX, $CY, $X, $Y, $color, $t) - There should be no need to call this function directly (it is called by imagefilledellipseaa()).

  • imagefilledellipseaa(&$im, $CX, $CY, $Width, $Height, $color) - This is the actual ellipse drawing function, it takes the same parameters as the built in imagefilledellipse() except it will draw an antialiased ellipse. For more detail see www.php.net.

Usage

To use the functions just include them into your page and then call the imagefilledellipseaa() in the same way that you would call imagefilledellipse() an example is shown below:-

<?php
// Include the functions.
require_once("gdext.php");

// Try to create the image.
$im = @imagecreatetruecolor(200, 200);

if (
$im)
{
    
// Set up the background.
    
$background = imagecolorallocate($im, 0x57, 0x82, 0xB9);
    
imagefilledrectangle($im, 1, 1, 198, 198, $background);

    
// Allocate the color to draw with.
    
$ellipse = imagecolorallocate($im, 0xB0, 0xC4, 0xDE);
  
      
// Draw the antialiased ellipse.
    
imagefilledellipseaa($im, 100, 50, 150, 50, $ellipse);
    
// Draw the normal ellipse underneath for comparison.
    
imagefilledellipse($im, 100, 150, 150, 50, $ellipse);
    
    
// Ouptput the image.            
    
header("Content-type: image/png");
    
imagepng($im);

    
// Release any memory associated with the image.
    
imagecolordeallocate($im, $red);
    
imagedestroy($im);
}
?>

This will produce the result here.

Future improvements

There are a number of things that could be improved, including:-

  • Cleaning up the code and properly commenting.

  • Improving the speed and efficiency

  • Producing an un-filled version

License

Feel free to copy this code and use it wherever you like but if you do use it I only ask that you acknowledge me (even if it just a comment in the code ;)).

Use these functions at your own risk I accept no responsiblity from anty damage arising from the use of these and provided no gaurantee that they work.

References

These functions were developed from the algorithm described in:-

http://homepage.smc.edu/kennedy_john/BELIPSE.PDF

© R. Parker 2005

Best viewed at 1024x768 or higher.