protected function _generateByGd($code, $width, $height)
{
$image = imagecreatetruecolor($width, $height);
$parts = explode(',', $this->_bgRGB);
$bgColor = imagecolorallocate($image, $parts[0], $parts[1], $parts[2]);
imagefilledrectangle($image, 0, 0, $width, $height, $bgColor);
$fontFile = $this->alias->resolve($this->_fonts[(int) (mt_rand() % count($this->_fonts))]);
$referenceFontSize = min($height, $width / $this->_length);
$x = 0;
$points[2] = mt_rand($referenceFontSize * 0.1, $referenceFontSize * 0.3);
$length = strlen($code);
/** @noinspection ForeachInvariantsInspection */
for ($i = 0; $i < $length; $i++) {
$fontSize = $referenceFontSize * mt_rand(800, 1000) / 1000;
$angle = mt_rand(-$this->_angleAmplitude, $this->_angleAmplitude);
$x += $points[2] - $x - round(mt_rand($fontSize * 0.1, $fontSize * 0.2));
$y = $height - ($height - $referenceFontSize) * mt_rand(0, 1000) / 1000;
$fgColor = imagecolorallocate($image, mt_rand(0, 240), mt_rand(0, 240), mt_rand(0, 240));
$points = imagettftext($image, $fontSize, $angle, $x, $y, $fgColor, $fontFile, $code[$i]);
for ($k = 0; $k < $this->_noiseCharCount; $k++) {
$letter = $this->_charset[(int) (mt_rand() % strlen($this->_charset))];
$fgColor = imagecolorallocate($image, mt_rand(0, 240), mt_rand(0, 240), mt_rand(0, 240));
imagettftext($image, $fontSize * 0.4 * $this->_rand_amplitude(0.1), mt_rand(-40, 40), round($x + mt_rand(-$fontSize * 1.5, $fontSize)), $height / 2 + mt_rand(-$fontSize * 0.5, $fontSize * 0.5), $fgColor, $fontFile, $letter);
}
}
$this->response->setContentType('image/jpeg');
ob_start();
imagejpeg($image, null, 90);
$this->response->setContent(ob_get_clean());
imagedestroy($image);
return $this->response;
}