Basit
Basit

Reputation: 17184

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 = $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

Upvotes: 3

Views: 3285

Answers (4)

Evan Kroske
Evan Kroske

Reputation: 4554

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.

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798686

cairo does antialiasing well.

Upvotes: 0

nategood
nategood

Reputation: 12005

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

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

Upvotes: 2

CJD
CJD

Reputation: 747

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.

Upvotes: 1

Related Questions