php image arrow line need to be smooth
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 开发者_Go百科= $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
Haven't tried anti-aliasing in GD myself, but it appears to be there...
http://uk.php.net/manual/en/function.imageantialias.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 does antialiasing well.
精彩评论