3

我在 php 中制作了一条线,到目前为止它的显示效果很好,但我现在遇到的问题是这条线不平滑,它显示为断边。以下是制作半径线的代码:

function draw_radius($img, $x1, $y1, $radius, $angle, $arrow_color, $arrow_length = 10, $arrow_width = 3)
{
    $x2 = $x1 + $radius * cos(deg2rad($angle-90));
    $y2 = $y1 + $radius * sin(deg2rad($angle-90));
    imageline($img, $x1, $y1, $x2, $y2, $arrow_color);

    $distance = sqrt(pow($x1 - $x2, 2) + pow($y1 - $y2, 2));
    $dx = $x2 + ($x1 - $x2) * $arrow_length / $distance;
    $dy = $y2 + ($y1 - $y2) * $arrow_length / $distance;
    $k = $arrow_width / $arrow_length;
    $x2o = $x2 - $dx;
    $y2o = $dy - $y2;
    $x3 = $y2o * $k + $dx;
    $y3 = $x2o * $k + $dy;
    $x4 = $dx - $y2o * $k;
    $y4 = $dy - $x2o * $k;
    imageline($img, $x1, $y1, $dx, $dy, $arrow_color);
    imageline($img, $x3, $y3, $x4, $y4, $arrow_color);
    imageline($img, $x3, $y3, $x2, $y2, $arrow_color);
    imageline($img, $x2, $y2, $x4, $y4, $arrow_color);


}

以下是指南针示例,我在上面画线。

指南针示例 http://img246.imageshack.us/img246/6329/compassx.png

4

4 回答 4

2

您需要使用具有抗锯齿功能的图像处理库。该技术的解释。我对您应该使用哪个库没有任何建议:我不使用 PHP 进行图像处理。

于 2010-02-21T20:17:44.917 回答
2

我自己还没有在GD中尝试过抗锯齿,但它似乎在那里......

http://uk.php.net/manual/en/function.imageantialias.php

于 2010-02-21T20:22:31.617 回答
1

你可以试试这个,但是按照他们的例子,它看起来并不好。您可以在评论中尝试其他一些选项。

于 2010-02-21T20:19:34.560 回答
0

cairo的抗锯齿效果很好。

于 2010-02-22T00:08:22.850 回答