More feature detection in WP_Image_Editor_Imagick::test().

Check existence of setIteratorIndex().

Props DH-Shredder, markoheijnen
see #22543



git-svn-id: http://core.svn.wordpress.org/trunk@22849 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Ryan Boren 2012-11-26 22:40:34 +00:00
parent 4e9e4bf2cf
commit e52a437bc2
1 changed files with 45 additions and 3 deletions

View File

@ -38,8 +38,48 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
* @return boolean * @return boolean
*/ */
public static function test( $args = array() ) { public static function test( $args = array() ) {
if ( ! extension_loaded( 'imagick' ) || ! is_callable( 'Imagick', 'queryFormats' ) )
$required_methods = array(
'clear',
'destroy',
'valid',
'getimage',
'writeimage',
'getimageblob',
'getimagegeometry',
'getimageformat',
'setimageformat',
'setimagecompression',
'setimagecompressionquality',
'setimagepage',
'scaleimage',
'cropimage',
'rotateimage',
'flipimage',
'flopimage',
);
// Check for requirements
if ( ! extension_loaded( 'imagick' ) ||
! class_exists( 'Imagick' ) ||
! is_callable( 'Imagick', 'queryFormats' ) ||
! class_exists( 'ImagickPixel' ) ||
! defined( 'imagick::COMPRESSION_JPEG' ) ||
array_diff( $required_methods, get_class_methods( 'Imagick' ) ) ) {
return false; return false;
}
/**
* setIteratorIndex is optional unless mime is an animated format.
* Here, we just say no if a user is attempting to
* edit a GIF and setIteratorIndex isn't available.
*/
if ( ( ! isset( $args['mime_type'] ) || $args['mime_type'] == 'image/gif' ) &&
! method_exists( 'Imagick', 'setIteratorIndex' ) ) {
return false;
}
return true; return true;
} }
@ -88,8 +128,10 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
if( ! $this->image->valid() ) if( ! $this->image->valid() )
return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file); return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file);
// Select the first frame to handle animated GIFs properly // Select the first frame to handle animated images properly
$this->image->setIteratorIndex(0); if ( is_callable( array( $this->image, 'setIteratorIndex' ) ) )
$this->image->setIteratorIndex(0);
$this->mime_type = $this->get_mime_type( $this->image->getImageFormat() ); $this->mime_type = $this->get_mime_type( $this->image->getImageFormat() );
} }
catch ( Exception $e ) { catch ( Exception $e ) {