diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 96c325b..002a71e 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -30,6 +30,7 @@ class Configuration implements ConfigurationInterface ->scalarNode('web_path')->defaultValue('%kernel.root_dir%/../web')->end() ->scalarNode('gc_freq')->defaultValue(100)->end() ->scalarNode('expiration')->defaultValue(60)->end() + ->scalarNode('quality')->defaultValue(15)->end() ->end() ; return $treeBuilder; diff --git a/Generator/CaptchaGenerator.php b/Generator/CaptchaGenerator.php index 2707406..24e6c60 100644 --- a/Generator/CaptchaGenerator.php +++ b/Generator/CaptchaGenerator.php @@ -58,7 +58,13 @@ class CaptchaGenerator { */ public $value; - public function __construct($value, $imageFolder, $webPath, $gcFreq, $expiration, $font, $fingerprint) + /** + * Captcha quality + * @var int + */ + public $quality; + + public function __construct($value, $imageFolder, $webPath, $gcFreq, $expiration, $font, $fingerprint, $quality) { $this->value = $value; $this->imageFolder = $imageFolder; @@ -68,6 +74,7 @@ class CaptchaGenerator { $this->font = $font; $this->fingerprint = $fingerprint; $this->use_fingerprint = (bool)$fingerprint; + $this->quality = intval($quality); } /** @@ -212,7 +219,7 @@ class CaptchaGenerator { // Renders it if (!$createFile) { ob_start(); - imagejpeg($out, null, 15); + imagejpeg($out, null, $this->quality); return ob_get_clean(); } else { // Check if folder exists and create it if not diff --git a/README.md b/README.md index 7cabb35..fa434bb 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ You can define the following type option : * **width**: the width of the captcha image (default=120) * **height**: the height of the captcha image (default=40) * **length**: the length of the captcha (number of chars, default 5) +* **quality**: jpeg quality of captchas (default=15) * **charset**: the charset used for code generation (default=abcdefhjkmnprstuvwxyz23456789) * **font**: the font to use (default=Generator/Font/captcha.ttf) * **keep_value**: the value will be the same until the form is posted, even if the page is refreshed (default=true) diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php index 862cb6c..2cdf270 100755 --- a/Type/CaptchaType.php +++ b/Type/CaptchaType.php @@ -83,6 +83,12 @@ class CaptchaType extends AbstractType */ protected $font; + /** + * Captcha quality + * @var int + */ + protected $quality; + /** * Maximum age of images in minutes * @var int @@ -117,6 +123,7 @@ class CaptchaType extends AbstractType $this->gcFreq = $config['gc_freq']; $this->expiration = $config['expiration']; $this->font = $config['font']; + $this->quality = $config['quality']; } public function buildForm(FormBuilder $builder, array $options) @@ -136,7 +143,7 @@ class CaptchaType extends AbstractType $fingerprint = $this->session->get($this->key.'_fingerprint'); } - $generator = new CaptchaGenerator($this->generateCaptchaValue(), $this->imageFolder, $this->webPath, $this->gcFreq, $this->expiration, $this->font, $fingerprint); + $generator = new CaptchaGenerator($this->generateCaptchaValue(), $this->imageFolder, $this->webPath, $this->gcFreq, $this->expiration, $this->font, $fingerprint, $this->quality); if ($this->asFile) { $view->set('captcha_code', $generator->getFile($this->width, $this->height));