php图像箭头线需要平滑

发布于 2024-08-22 04:58:36 字数 1151 浏览 4 评论 0原文

我在 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< /a>

im making a line in php and so far its showing fine, but what problem im getting now is the line is not being smooth, it shows as breaking edges. following is the code for making radius line:

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


}

following is the compass example, which im drawing line on.

compass example http://img246.imageshack.us/img246/6329/compassx.png

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

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

发布评论

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

评论(4

若有似无的小暗淡 2024-08-29 04:58:36

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

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

Haven't tried anti-aliasing in GD myself, but it appears to be there...

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

赤濁 2024-08-29 04:58:36

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

You need to use an image processing library that has anti-aliasing. An explanation of the technique. I have no suggestions for which library you should use: I don't use PHP for image processing.

ㄖ落Θ余辉 2024-08-29 04:58:36

您可以尝试这个,但是根据他们的示例,似乎没有伟大的。您可以在评论中尝试其他一些选项。

You could try this, but going by their example, it doesn't seem great. There are a few other options you could try in the comments.

披肩女神 2024-08-29 04:58:36

cairo 抗锯齿效果很好。

cairo does antialiasing well.

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