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

I am creating an image of a PHP script that will create circles with a given radius.

I used:

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

but I hate the rough edges that he produces. So I was thinking about creating or using a circle font, which I will post using:

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

To make the font create a circle with a smooth edge. My problem is that the font size matches the "radius size".

Any ideas? Or maybe the PHP class that will create the smooth edge on the circle will be big!

Thanks.

+4
source share
4 answers

Smart idea, I like it!

But perhaps this PHP class is already doing the trick: Smooth filled arcs / ellipses for PHP (GD)

In many cases, websites need dynamically generated 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 smooth. So I wrote a PHP function to render filled smoothed elliptical arcs or filled smoothed ellipses (as well as circles ..) with PHP easily. Drawing these filled arcs is now single-line.

+2
source

For quick and dirty smoothing, make the image twice the right 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); 
+6
source

Cairo smooths well.

+1
source

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

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

0
source

Source: https://habr.com/ru/post/1304104/


All Articles