Skip to content

Commit

Permalink
added option to set line color
Browse files Browse the repository at this point in the history
  • Loading branch information
didatus committed Mar 23, 2020
1 parent 6088ad3 commit cb295bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
demo/*.jpg
demo/*.pgm
demo/temp/
Expand Down
24 changes: 23 additions & 1 deletion src/Gregwar/Captcha/CaptchaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class CaptchaBuilder implements CaptchaBuilderInterface
*/
protected $textColor = array();

/**
* @var array
*/
protected $lineColor = array();

/**
* @var array
*/
Expand Down Expand Up @@ -229,6 +234,13 @@ public function setBackgroundColor($r, $g, $b)
return $this;
}

public function setLineColor($r, $g, $b)
{
$this->lineColor = array($r, $g, $b);

return $this;
}

/**
* Sets the ignoreAllEffects value
*
Expand Down Expand Up @@ -257,8 +269,18 @@ public function setBackgroundImages(array $backgroundImages)
*/
protected function drawLine($image, $width, $height, $tcol = null)
{
$red = $this->rand(100, 255);
$green = $this->rand(100, 255);
$blue = $this->rand(100, 255);

if (!empty($this->lineColor)) {
$red = $this->lineColor[0];
$green = $this->lineColor[1];
$blue = $this->lineColor[2];
}

if ($tcol === null) {
$tcol = imagecolorallocate($image, $this->rand(100, 255), $this->rand(100, 255), $this->rand(100, 255));
$tcol = imagecolorallocate($image, $red, $green, $blue);
}

if ($this->rand(0, 1)) { // Horizontal
Expand Down

0 comments on commit cb295bd

Please sign in to comment.