You are here

function signaturefield_drawline in SignatureField 6

Same name and namespace in other branches
  1. 7.2 signaturefield.module \signaturefield_drawline()
  2. 7 signaturefield.module \signaturefield_drawline()

Draws a thick line Changing the thickness of a line using imagesetthickness doesn't produce as nice of result

Parameters

object $src_image:

int $startX:

int $startY:

int $endX:

int $endY:

object $colour:

int $thickness:

Return value

void

1 call to signaturefield_drawline()
signaturefield_json_to_image in ./signaturefield.module

File

./signaturefield.module, line 79
Signature Field module.

Code

function signaturefield_drawline($src_image, $startX, $startY, $endX, $endY, $color, $thickness) {
  $angle = atan2($startY - $endY, $endX - $startX);
  $dist_x = $thickness * sin($angle);
  $dist_y = $thickness * cos($angle);
  $x1 = ceil($startX + $dist_x);
  $y1 = ceil($startY + $dist_y);
  $x2 = ceil($endX + $dist_x);
  $y2 = ceil($endY + $dist_y);
  $x3 = ceil($endX - $dist_x);
  $y3 = ceil($endY - $dist_y);
  $x4 = ceil($startX - $dist_x);
  $y4 = ceil($startY - $dist_y);
  $array = array(
    $x1,
    $y1,
    $x2,
    $y2,
    $x3,
    $y3,
    $x4,
    $y4,
  );
  imagefilledpolygon($src_image, $array, count($array) / 2, $color);
}