views:

389

answers:

4

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

+2  A: 

You need to use an image processing library that has anti-aliasing. For an explanation of the technique, see http://en.wikipedia.org/wiki/Anti_aliasing. I have no suggestions for which library you should use; I don't use PHP for image processing.

Evan Kroske
+1  A: 

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.

CJD
+2  A: 

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

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

nategood
i tried anti-aliasing on it, no effect changed. maybe there is different way of applying anti-aliasing!
Basit
A: 

cairo does antialiasing well.

Ignacio Vazquez-Abrams