我在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);
}
以下是指南针示例,我正在画线.
compass example http://img246.imageshack.us/img246/6329/compassx.png
解决方法:
我自己还没有尝试过GD中的抗锯齿功能,但是它似乎在那里…
http://uk.php.net/manual/en/function.imageantialias.php