/** * Set the text into the image * * @param string $text * The captcha text * * @param integer $width * Image width * * @param integer $height * Image height */ private function setText($text, $width, $height) { $strlen = strlen($text); $allFonts = Font::get(); if (is_int(self::$padding)) { $maxWidth = $width - self::$padding; $maxHeight = $height - self::$padding; } else { $maxWidth = $width - $width * self::$padding; $maxHeight = $height - $height * self::$padding; } $letters = $previous = array(); $fontSize = 14; while (true) { $letters = $this->getLetters($text, $strlen, $fontSize += 2, $allFonts, $width, $height, $maxWidth, $maxHeight); if ($letters === false) { $letters = $previous; break; } $previous = $letters; } if (self::$noisePoints) { $this->noisePoints($width, $height); } if (self::$noiseLines) { $this->noiseLines($width, $height); } $x = intval(($width - array_sum(array_map(function ($row) { return $row['width']; }, $letters))) / 2); foreach ($letters as $letter) { imagettftext($this->image, $letter['size'], $letter['angle'], $x, $letter['y'], imagecolorallocate($this->image, 115, 115, 115), $letter['font'], $letter['letter']); $x += $letter['width']; } }