#!perl -w use Imager; use strict; my $im = Imager->new(xsize=>200, ysize=>200); thick_line($im, 10, 10, 100, 190, 5, color=>'#F00'); thick_line($im, 10, 100, 190, 40, 20, fill=>{ hatch=>'check2x2', fg=>'#0f0', bg=>'#088' }); $im->write(file=>'thickline.png'); sub thick_line { my ($im, $x1, $y1, $x2, $y2, $width, @extras) = @_; my $dx = $x2 - $x1; my $dy = $y2 - $y1; my $d = sqrt($dx * $dx + $dy * $dy); my $cos = $dx / $d; my $sin = $dy / $d; my $wcos = $width * $cos / 2; my $wsin = $width * $sin / 2; my @pts = ( [ $x1 + $wsin, $y1 - $wcos ], [ $x1 - $wsin, $y1 + $wcos ], [ $x2 - $wsin, $y2 + $wcos ], [ $x2 + $wsin, $y2 - $wcos ], ); $im->polygon(points=>\@pts, @extras) or die $im->errstr; }