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:
parent
4e9e4bf2cf
commit
e52a437bc2
|
@ -38,8 +38,48 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
|
|||
* @return boolean
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
@ -88,8 +128,10 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
|
|||
if( ! $this->image->valid() )
|
||||
return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file);
|
||||
|
||||
// Select the first frame to handle animated GIFs properly
|
||||
$this->image->setIteratorIndex(0);
|
||||
// Select the first frame to handle animated images properly
|
||||
if ( is_callable( array( $this->image, 'setIteratorIndex' ) ) )
|
||||
$this->image->setIteratorIndex(0);
|
||||
|
||||
$this->mime_type = $this->get_mime_type( $this->image->getImageFormat() );
|
||||
}
|
||||
catch ( Exception $e ) {
|
||||
|
|
Loading…
Reference in New Issue