[Configuration] Added JPEG quality node (fixes #13)
This commit is contained in:
parent
53e5605103
commit
f9c57e6970
|
@ -30,6 +30,7 @@ class Configuration implements ConfigurationInterface
|
||||||
->scalarNode('web_path')->defaultValue('%kernel.root_dir%/../web')->end()
|
->scalarNode('web_path')->defaultValue('%kernel.root_dir%/../web')->end()
|
||||||
->scalarNode('gc_freq')->defaultValue(100)->end()
|
->scalarNode('gc_freq')->defaultValue(100)->end()
|
||||||
->scalarNode('expiration')->defaultValue(60)->end()
|
->scalarNode('expiration')->defaultValue(60)->end()
|
||||||
|
->scalarNode('quality')->defaultValue(15)->end()
|
||||||
->end()
|
->end()
|
||||||
;
|
;
|
||||||
return $treeBuilder;
|
return $treeBuilder;
|
||||||
|
|
|
@ -58,7 +58,13 @@ class CaptchaGenerator {
|
||||||
*/
|
*/
|
||||||
public $value;
|
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->value = $value;
|
||||||
$this->imageFolder = $imageFolder;
|
$this->imageFolder = $imageFolder;
|
||||||
|
@ -68,6 +74,7 @@ class CaptchaGenerator {
|
||||||
$this->font = $font;
|
$this->font = $font;
|
||||||
$this->fingerprint = $fingerprint;
|
$this->fingerprint = $fingerprint;
|
||||||
$this->use_fingerprint = (bool)$fingerprint;
|
$this->use_fingerprint = (bool)$fingerprint;
|
||||||
|
$this->quality = intval($quality);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -212,7 +219,7 @@ class CaptchaGenerator {
|
||||||
// Renders it
|
// Renders it
|
||||||
if (!$createFile) {
|
if (!$createFile) {
|
||||||
ob_start();
|
ob_start();
|
||||||
imagejpeg($out, null, 15);
|
imagejpeg($out, null, $this->quality);
|
||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
} else {
|
} else {
|
||||||
// Check if folder exists and create it if not
|
// Check if folder exists and create it if not
|
||||||
|
|
|
@ -100,6 +100,7 @@ You can define the following type option :
|
||||||
* **width**: the width of the captcha image (default=120)
|
* **width**: the width of the captcha image (default=120)
|
||||||
* **height**: the height of the captcha image (default=40)
|
* **height**: the height of the captcha image (default=40)
|
||||||
* **length**: the length of the captcha (number of chars, default 5)
|
* **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)
|
* **charset**: the charset used for code generation (default=abcdefhjkmnprstuvwxyz23456789)
|
||||||
* **font**: the font to use (default=Generator/Font/captcha.ttf)
|
* **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)
|
* **keep_value**: the value will be the same until the form is posted, even if the page is refreshed (default=true)
|
||||||
|
|
|
@ -83,6 +83,12 @@ class CaptchaType extends AbstractType
|
||||||
*/
|
*/
|
||||||
protected $font;
|
protected $font;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Captcha quality
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $quality;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum age of images in minutes
|
* Maximum age of images in minutes
|
||||||
* @var int
|
* @var int
|
||||||
|
@ -117,6 +123,7 @@ class CaptchaType extends AbstractType
|
||||||
$this->gcFreq = $config['gc_freq'];
|
$this->gcFreq = $config['gc_freq'];
|
||||||
$this->expiration = $config['expiration'];
|
$this->expiration = $config['expiration'];
|
||||||
$this->font = $config['font'];
|
$this->font = $config['font'];
|
||||||
|
$this->quality = $config['quality'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilder $builder, array $options)
|
public function buildForm(FormBuilder $builder, array $options)
|
||||||
|
@ -136,7 +143,7 @@ class CaptchaType extends AbstractType
|
||||||
$fingerprint = $this->session->get($this->key.'_fingerprint');
|
$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) {
|
if ($this->asFile) {
|
||||||
$view->set('captcha_code', $generator->getFile($this->width, $this->height));
|
$view->set('captcha_code', $generator->getFile($this->width, $this->height));
|
||||||
|
|
Loading…
Reference in New Issue