开发者

PHP: creating a smooth edged circle, image or font?

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

I used:

<?php
imagefilledellipse ( $image,开发者_C百科 $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.


for quick and dirty anti-aliasing, make the image twice the desired size, then down-sample to the desired size.

$circleSize=90;
$canvasSize=100;

$imageX2 = imagecreatetruecolor($canvasSize*2, $canvasSize*2);

$bg = imagecolorallocate($imageX2, 255, 255, 255);

$col_ellipse = imagecolorallocate($imageX2, 204, 0, 0);

imagefilledellipse($imageX2, $canvasSize, $canvasSize, $circleSize*2, $circleSize*2, $col_ellipse);

$imageOut = imagecreatetruecolor($canvasSize, $canvasSize);
imagecopyresampled($imageOut, $imageX2, 0, 0, 0, 0, $canvasSize, $canvasSize, $canvasSize*2, $canvasSize*2);

header("Content-type: image/png");
imagepng($imageOut);


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.


Cairo does antialiasing well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜