Permalink
Browse files

ImageMagick checking code now takes into account supported image files.

  • Loading branch information...
1 parent f907506 commit c089442867d041f3ae5b8e882de860f4f4930868 @resurtm resurtm committed Dec 9, 2012
Showing with 33 additions and 10 deletions.
  1. +4 −0 UPGRADE
  2. +19 −6 framework/web/widgets/captcha/CCaptcha.php
  3. +10 −4 requirements/index.php
View
@@ -48,6 +48,10 @@ Upgrading from v1.1.12
$alias = $this->owner->getTableAlias();
$criteria->condition = $alias.'.myfield = 1';
+- Make sure you are using `CCaptcha::checkRequirements()` method for checking whether CAPTCHA could be rendered successfully in your environment.
+ `extension_loaded('gd')` expression is not enough and wrong because CAPTCHA could be rendered via ImageMagick with fallback to GD since 1.1.13
+ (thus checking code is not simple as it seems).
+
Upgrading from v1.1.11
----------------------
- Changes in CCookieCollection::add() (introduced in 1.1.11) were reverted as they were triggering E_STRICT on some old PHP-versions
@@ -157,19 +157,32 @@ public function registerClientScript()
* @param string extension name to be checked. Possible values are 'gd', 'imagick' and null.
* Default value is null meaning that both extensions will be checked. This parameter
* is available since 1.1.13.
- * @return boolean true if ImageMagick extension or GD with FreeType support is loaded, otherwise false
+ * @return boolean true if ImageMagick extension with PNG support or GD with FreeType support is loaded,
+ * otherwise false
* @since 1.1.5
*/
public static function checkRequirements($extension=null)
{
- if(($extension===null || $extension=='imagick') && extension_loaded('imagick'))
- return true;
- elseif(($extension===null || $extension=='gd') && extension_loaded('gd'))
+ if(extension_loaded('imagick'))
+ {
+ $imagick=new Imagick();
+ $imagickFormats=$imagick->queryFormats('PNG');
+ }
+ if(extension_loaded('gd'))
+ {
+ $gdInfo=gd_info();
+ }
+ if($extension===null)
{
- $gdinfo=gd_info();
- if($gdinfo['FreeType Support'])
+ if(isset($imagickFormats) && in_array('PNG',$imagickFormats))
+ return true;
+ if(isset($gdInfo) && $gdInfo['FreeType Support'])
return true;
}
+ elseif($extension=='imagick' && isset($imagickFormats) && in_array('PNG',$imagickFormats))
+ return true;
+ elseif($extension=='gd' && isset($gdInfo) && $gdInfo['FreeType Support'])
+ return true;
return false;
}
}
View
@@ -126,7 +126,7 @@ class_exists("DOMDocument",false),
'<a href="http://www.yiiframework.com/doc/api/CWebService">CWebService</a>, <a href="http://www.yiiframework.com/doc/api/CWebServiceAction">CWebServiceAction</a>',
''),
array(
- t('yii','GD extension with<br />FreeType support<br />or ImageMagick extension'),
+ t('yii','GD extension with<br />FreeType support<br />or ImageMagick<br />extension with<br />PNG support'),
false,
'' === $message=checkCaptchaSupport(),
'<a href="http://www.yiiframework.com/doc/api/CCaptchaAction">CCaptchaAction</a>',
@@ -167,11 +167,17 @@ function checkServerVar()
function checkCaptchaSupport()
{
if(extension_loaded('imagick'))
+ {
+ $imagick=new Imagick();
+ $imagickFormats=$imagick->queryFormats('PNG');
+ }
+ if(extension_loaded('gd'))
+ $gdInfo=gd_info();
+ if(isset($imagickFormats) && in_array('PNG',$imagickFormats))
return '';
- elseif(extension_loaded('gd'))
+ elseif(isset($gdInfo))
{
- $gdinfo=gd_info();
- if($gdinfo['FreeType Support'])
+ if($gdInfo['FreeType Support'])
return '';
return t('yii','GD installed,<br />FreeType support not installed');
}

0 comments on commit c089442

Please sign in to comment.