WP_Image_Editor_Imagick::test()public staticWP 3.5.0

Checks to see if current environment supports Imagick.

We require Imagick 2.2.0 or greater, based on whether the queryFormats() method can be called statically.

Method of the class: WP_Image_Editor_Imagick{}

No Hooks.

Return

true|false.

Usage

$result = WP_Image_Editor_Imagick::test( $args );
$args(array)
-
Default: array()

Changelog

Since 3.5.0 Introduced.

WP_Image_Editor_Imagick::test() code WP 6.4.3

public static function test( $args = array() ) {

	// First, test Imagick's extension and classes.
	if ( ! extension_loaded( 'imagick' ) || ! class_exists( 'Imagick', false ) || ! class_exists( 'ImagickPixel', false ) ) {
		return false;
	}

	if ( version_compare( phpversion( 'imagick' ), '2.2.0', '<' ) ) {
		return false;
	}

	$required_methods = array(
		'clear',
		'destroy',
		'valid',
		'getimage',
		'writeimage',
		'getimageblob',
		'getimagegeometry',
		'getimageformat',
		'setimageformat',
		'setimagecompression',
		'setimagecompressionquality',
		'setimagepage',
		'setoption',
		'scaleimage',
		'cropimage',
		'rotateimage',
		'flipimage',
		'flopimage',
		'readimage',
		'readimageblob',
	);

	// Now, test for deep requirements within Imagick.
	if ( ! defined( 'imagick::COMPRESSION_JPEG' ) ) {
		return false;
	}

	$class_methods = array_map( 'strtolower', get_class_methods( 'Imagick' ) );
	if ( array_diff( $required_methods, $class_methods ) ) {
		return false;
	}

	return true;
}