From 4a5b2a4c484b5c7c510f27e6f9bc83b60739546e Mon Sep 17 00:00:00 2001 From: Gregwar Date: Fri, 9 Sep 2011 19:51:07 +0200 Subject: [PATCH] Fixed Generator to support any width --- Generator/CaptchaGenerator.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Generator/CaptchaGenerator.php b/Generator/CaptchaGenerator.php index 2981c45..c41e468 100644 --- a/Generator/CaptchaGenerator.php +++ b/Generator/CaptchaGenerator.php @@ -41,7 +41,13 @@ class CaptchaGenerator { } // Write CAPTCHA text - imagettftext($i, 28, 0, 5, 32, $col, dirname(__FILE__).'/Font/captcha.ttf', $this->value); + $size = $width/5.0; + $font = __DIR__.'/Font/captcha.ttf'; + $box = imagettfbbox($size, 0, $font, $this->value); + $txt_width = $box[2] - $box[0]; + $txt_height = $box[1] - $box[7]; + + imagettftext($i, $size, 0, ($width-$txt_width)/2, ($height-$txt_height)/2+$size, $col, $font, $this->value); // Distort the image $X = mt_rand(0, $width);