php图像箭头线需要平滑
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我自己没有尝试过 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
您需要使用具有抗锯齿功能的图像处理库。 该技术的说明。我没有建议您应该使用哪个库:我不使用 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.
您可以尝试这个,但是根据他们的示例,似乎没有伟大的。您可以在评论中尝试其他一些选项。
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.
cairo 抗锯齿效果很好。
cairo does antialiasing well.