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

柔情痞子 提交于 2020-01-22 15:22:46

问题


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.


回答1:


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.




回答2:


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);



回答3:


Cairo does antialiasing well.



来源:https://stackoverflow.com/questions/2444340/php-creating-a-smooth-edged-circle-image-or-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!