带缺陷的圆弧绘制

Arc draw with imperfections

这是我的 php 文件 (arc.php),它应该会产生一个粗半弧:

<?php
$img = imagecreatetruecolor(2000, 1000);    
$white = imagecolorallocate($img, 255, 255, 255);
imagesetthickness($img, 200);
imagearc($img, 1000, 1000, 1900, 1900,  180, 360, $white);
imagepng($img);
imagedestroy($img);


图像是通过cli生成的:

php arc.php > arc.png 


到目前为止,一切顺利...现在,有人知道为什么我在图像中出现这些瑕疵吗?

imagesetthicknesscomments in the documentation 似乎暗示椭圆和圆弧不适合厚度设置。这是一个错误还是一个功能是有争议的。无论如何,建议的解决方法是使用较小的厚度并反复绘制越来越大的形状。

在你的情况下,它看起来像:

<?php
$img = imagecreatetruecolor(2000, 1000);
$white = imagecolorallocate($img, 255, 255, 255);

// Slightly thicker than 1 pixel to compensate pixel aliasing
imagesetthickness($img, 2);

$thickness = 200;
for ($i = $thickness; $i > 0; $i--) {
    imagearc($img, 1000, 1000, 1900 - $i, 1900 - $i,  180, 360, $white);
}

imagepng($img);
imagedestroy($img);

生成以下图像:
您可能需要稍微调整一下结果,但这应该足以让您开始正确的道路。