Voting

: nine plus zero?
(Example: nine)

The Note You're Voting On

meid at gmx dot at
19 years ago
Some simple code to draw lines with specific thickness using "imagefilledpolygon". Useful if your gdlib does not support "imagesetthickness".

<?
function dickelinie($img,$start_x,$start_y,$end_x,$end_y,$color,$thickness)
{
$angle=(atan2(($start_y - $end_y),($end_x - $start_x)));

$dist_x=$thickness*(sin($angle));
$dist_y=$thickness*(cos($angle));

$p1x=ceil(($start_x + $dist_x));
$p1y=ceil(($start_y + $dist_y));
$p2x=ceil(($end_x + $dist_x));
$p2y=ceil(($end_y + $dist_y));
$p3x=ceil(($end_x - $dist_x));
$p3y=ceil(($end_y - $dist_y));
$p4x=ceil(($start_x - $dist_x));
$p4y=ceil(($start_y - $dist_y));

$array=array(0=>$p1x,$p1y,$p2x,$p2y,$p3x,$p3y,$p4x,$p4y);
imagefilledpolygon ( $img, $array, (count($array)/2), $color );
}
// Example:
header ("Content-type: image/jpeg");
$img = ImageCreate (210, 210) or die("Cannot Initialize new GD image stream ");
$backgroundcolor = ImageColorAllocate ($img, 255, 255, 255);
$orange = ImageColorAllocate($img, 252, 102, 4);
dickelinie($img, 10, 10, 10, 200,$orange,2);
dickelinie($img, 10, 200, 200, 10,$orange,2);
dickelinie($img, 200, 10, 200, 200,$orange,2);
imagejpeg($img);
ImageDestroy($img);

?>

<< Back to user notes page

To Top