mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Fixes #8284: Added \yii\captcha\CaptchaAction::$imageLibrary
property allowing to set image rendering library
This commit is contained in:

committed by
Alexander Makarov

parent
2a1764f97a
commit
742f106ec0
@ -44,6 +44,7 @@ Yii Framework 2 Change Log
|
|||||||
- Enh #4104: Added `yii\filters\auth\AuthMetod::optional` for optional authentification in all child classes (SilverFire)
|
- Enh #4104: Added `yii\filters\auth\AuthMetod::optional` for optional authentification in all child classes (SilverFire)
|
||||||
- Enh #7566: Improved `\yii\validators\CompareValidator` default messages (slinstj)
|
- Enh #7566: Improved `\yii\validators\CompareValidator` default messages (slinstj)
|
||||||
- Enh #7581: Added ability to specify range using anonymous function in `RangeValidator` (RomeroMsk)
|
- Enh #7581: Added ability to specify range using anonymous function in `RangeValidator` (RomeroMsk)
|
||||||
|
- Enh #8284: Added `\yii\captcha\CaptchaAction::$imageLibrary` property allowing to set image rendering library (AnatolyRugalev)
|
||||||
- Enh #8613: `yii\widgets\FragmentCache` will not store empty content anymore which fixes some problems related to `yii\filters\PageCache` (kidol)
|
- Enh #8613: `yii\widgets\FragmentCache` will not store empty content anymore which fixes some problems related to `yii\filters\PageCache` (kidol)
|
||||||
- Enh #8649: Added total applied migrations to final report (vernik91)
|
- Enh #8649: Added total applied migrations to final report (vernik91)
|
||||||
- Enh #9282: Improved JSON error handling to support PHP 5.5 error codes (freezy-sk)
|
- Enh #9282: Improved JSON error handling to support PHP 5.5 error codes (freezy-sk)
|
||||||
|
@ -98,6 +98,11 @@ class CaptchaAction extends Action
|
|||||||
* If not set, it means the verification code will be randomly generated.
|
* If not set, it means the verification code will be randomly generated.
|
||||||
*/
|
*/
|
||||||
public $fixedVerifyCode;
|
public $fixedVerifyCode;
|
||||||
|
/**
|
||||||
|
* @var string the rendering library to use. Currently supported only 'gd' and 'imagick'.
|
||||||
|
* If not set, library will be determined automatically.
|
||||||
|
*/
|
||||||
|
public $imageLibrary;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -236,13 +241,21 @@ class CaptchaAction extends Action
|
|||||||
* Renders the CAPTCHA image.
|
* Renders the CAPTCHA image.
|
||||||
* @param string $code the verification code
|
* @param string $code the verification code
|
||||||
* @return string image contents
|
* @return string image contents
|
||||||
|
* @throws InvalidConfigException if imageLibrary is not supported
|
||||||
*/
|
*/
|
||||||
protected function renderImage($code)
|
protected function renderImage($code)
|
||||||
{
|
{
|
||||||
if (Captcha::checkRequirements() === 'gd') {
|
if (isset($this->imageLibrary)) {
|
||||||
return $this->renderImageByGD($code);
|
$imageLibrary = $this->imageLibrary;
|
||||||
} else {
|
} else {
|
||||||
|
$imageLibrary = Captcha::checkRequirements();
|
||||||
|
}
|
||||||
|
if ($imageLibrary === 'gd') {
|
||||||
|
return $this->renderImageByGD($code);
|
||||||
|
} elseif ($imageLibrary === 'imagick') {
|
||||||
return $this->renderImageByImagick($code);
|
return $this->renderImageByImagick($code);
|
||||||
|
} else {
|
||||||
|
throw new InvalidConfigException("Defined library '{$imageLibrary}' is not supported");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user