Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashed lines #202

Open
x-zolezzi opened this issue Sep 2, 2017 · 1 comment
Open

Dashed lines #202

x-zolezzi opened this issue Sep 2, 2017 · 1 comment

Comments

@x-zolezzi
Copy link

x-zolezzi commented Sep 2, 2017

Hi,

I have create a new function to draw dashed line :

  //
  // Draws a dashed line.
  //
  //  $x1* (int) - The x coordinate for the first point.
  //  $y1* (int) - The y coordinate for the first point.
  //  $x2* (int) - The x coordinate for the second point.
  //  $y2* (int) - The y coordinate for the second point.
  //  $color (string|array) - The line color.
  //  $thickness (int) - The line thickness (default 1).
  //  $dashedLength (int) - Length of the dashed (default 4)
  //
  // Returns a SimpleImage object.
  //
  public function lineDashed($x1, $y1, $x2, $y2, $color, $thickness = 1, $dashedLength = 4) {
    // Allocate the color
    $color = $this->allocateColor($color);

    // Draw a line
    imagesetthickness($this->image, $thickness);
    $transparent = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
    $style = array();
    for ($i = 0; $i < $dashedLength; $i++) {
        $style[] = $color;
    }
    for ($i = 0; $i < $dashedLength; $i++) {
        $style[] = $transparent;
    }
    imagesetstyle($this->image, $style);
    imageline($this->image, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);

    return $this;
  }
@claviska
Copy link
Owner

claviska commented Sep 2, 2017 via email

@claviska claviska changed the title [New feature] Draw Line Dashed Dashed lines Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants