PHP:创建边缘光滑的圆圈、图像或字体?

发布于 2024-08-24 17:51:37 字数 425 浏览 3 评论 0原文

我正在制作一个 PHP 图像脚本,它将在给定的半径处创建圆圈。

我用过:

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

但讨厌它产生的粗糙边缘。所以我正在考虑制作或使用圆形字体,我将使用以下方式输出:

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

这样字体将产生一个具有平滑边缘的圆形。我的问题是使“字体大小”与“半径大小”匹配。

有什么想法吗?或者也许一个能够在圆上产生平滑边缘的 PHP 类会很棒!

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

走走停停 2024-08-31 17:51:37

为了快速而肮脏的抗锯齿,请将图像设为所需尺寸的两倍,然后将采样缩小到所需尺寸。

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

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);
奢望 2024-08-31 17:51:37

聪明的主意,我喜欢!

但也许这个 PHP 类已经做到了这一点: Antialiasedfilled Arcs/Ellipses for PHP (GD)

在许多情况下,网站需要动态创建图像:饼图、圆角、菜单按钮等。这个列表是无穷无尽的。 PHP,或更准确地说是 GD 库,提供填充椭圆弧和椭圆,但它们没有抗锯齿。因此,我编写了一个 PHP 函数,可以轻松地使用 PHP 渲染填充抗锯齿椭圆弧或填充抗锯齿椭圆(以及圆..)。绘制这些填充弧线现在只需一行即可。

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.

折戟 2024-08-31 17:51:37

Cairo 抗锯齿效果很好。

Cairo does antialiasing well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文