More feature detection in WP_Image_Editor_Imagick::test().
Check existence of setIteratorIndex(). Props DH-Shredder, markoheijnen see #22543 git-svn-id: https://develop.svn.wordpress.org/trunk@22849 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
340a772e73
commit
40f11fff98
|
@ -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 ) {
|
||||||
|
|
Loading…
Reference in New Issue