Skip to content

Commit

Permalink
Merge pull request Gregwar#29 from whyte624/master
Browse files Browse the repository at this point in the history
bugfix division by zero
  • Loading branch information
Gregwar committed Sep 11, 2015
2 parents 00f63c2 + 830f38f commit 1240ab9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions CaptchaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,13 @@ protected function postEffect($image)
*/
protected function writePhrase($image, $phrase, $font, $width, $height)
{
$length = strlen($phrase);
if ($length === 0) {
return imagecolorallocate($image, 0, 0, 0);
}

// Gets the text size and start position
$size = $width / strlen($phrase) - $this->rand(0, 3) - 1;
$size = $width / $length - $this->rand(0, 3) - 1;
$box = imagettfbbox($size, 0, $font, $phrase);
$textWidth = $box[2] - $box[0];
$textHeight = $box[1] - $box[7];
Expand All @@ -333,7 +338,6 @@ protected function writePhrase($image, $phrase, $font, $width, $height)
$col = imagecolorallocate($image, $textColor[0], $textColor[1], $textColor[2]);

// Write the letters one by one, with random angle
$length = strlen($phrase);
for ($i=0; $i<$length; $i++) {
$box = imagettfbbox($size, 0, $font, $phrase[$i]);
$w = $box[2] - $box[0];
Expand Down

0 comments on commit 1240ab9

Please sign in to comment.