views:

457

answers:

3

I'm making a PHP image script that will create circles at a given radius.

I used:

<?php
imagefilledellipse ( $image, $cx, $cy, $w, $h, $color );
?>

but hate the rough edges it produces. So I was thinking of making or using a circle font that I will output using:

<?php
 imagettftext ( $image, $size, $angle, $x, $y, $color, 'fontfile.ttf', $text );
?>

So that the font will produce a circle that has a smooth edge. My problem is making the "font size" match the "radius size".

Any ideas? Or maybe a PHP class that will produce a smooth edge on a circle would be great!

Thank you.

A: 

Cairo does antialiasing well.

Ignacio Vazquez-Abrams
But needs to be installed/compiled into PHP and can't do bitmap output (correct me if I'm wrong.)
Pekka
@Pekka: It can do PNG and JPEG output (perhaps the word you were looking for was "raster"?).
Ignacio Vazquez-Abrams
You're right, sorry. http://www.php.net/manual/en/function.cairo-surface-write-to-png.php
Pekka
+1  A: 

Clever idea, I like that!

But maybe this PHP class already does the trick: Antialiased filled Arcs/Ellipses for PHP (GD)

In many cases websites need dynamically created images: pie charts, rounded corners, menu buttons, etc. This list is endless. PHP, or more precisely the GD library, provides filled elliptical arcs and ellipses, but they are not antialiased. Therefore I have written a PHP function to render filled antialiased elliptical arcs or filled antialiased ellipses (as well as circles..) with PHP easily. Drawing these filled arcs is now a one-liner.

Pekka
The "PHP Class which creates rounded corners (Version 2.0)" was actually perfect for what I needed. Allows to give a radius, color, and even a border.
Chad Whitaker
A: 

This article has what you are looking for: http://www.personal.3d-box.com/php/filledellipseaa.php

Alternately, you can make your own by translating Xiaolin Wu's fast AA circle algorithm from C: http://landkey.net/d/L/J/RF/index.php

Chris Perkins