Skip to content

Commit

Permalink
Phrase in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregwar committed Dec 27, 2012
1 parent 09f2db0 commit 47701eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions CaptchaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,21 @@ public function getPhrase()
return $this->phrase;
}

public function __construct($phrase = null)
{
if ($phrase === null) {
$phrase = PhraseBuilder::build();
}

$this->phrase = $phrase;
}

/**
* Instantiation
*/
public static function create()
public static function create($phrase = null)
{
return new self;
return new self($phrase);
}

/**
Expand Down Expand Up @@ -170,7 +179,7 @@ protected function writePhrase($image, $phrase, $font, $width, $height)
/**
* Generate the image
*/
public function build($phrase = null, $width = 150, $height = 40, $font = null, $fingerprint = null)
public function build($width = 150, $height = 40, $font = null, $fingerprint = null)
{
if (null !== $fingerprint) {
$this->fingerprint = $fingerprint;
Expand All @@ -184,19 +193,13 @@ public function build($phrase = null, $width = 150, $height = 40, $font = null,
$font = __DIR__ . '/Font/captcha'.$this->rand(0, 5).'.ttf';
}

if ($phrase === null) {
$phrase = PhraseBuilder::build();
}

$this->phrase = $phrase;

$image = imagecreatetruecolor($width, $height);
$bg = imagecolorallocate($image, $this->rand(180, 255), $this->rand(180, 255), $this->rand(180, 255));
$this->background = $bg;
imagefill($image, 0, 0, $bg);

// Write CAPTCHA text
$distort = $this->writePhrase($image, $phrase, $font, $width, $height);
$distort = $this->writePhrase($image, $this->phrase, $font, $width, $height);

// Apply effects
$square = $width * $height;
Expand Down
2 changes: 1 addition & 1 deletion demo/output.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
header('Content-type: image/jpeg');

CaptchaBuilder::create()
->build()
->build(300, 70)
->output(20)
;

0 comments on commit 47701eb

Please sign in to comment.