Choosing your PHP Image Extension for WordPress

WordPress supports two different PHP image processing extensions — ImageMagick and GD — with a preference for ImageMagick over GD (even when ImageMagick is not installed). The GD extension can still be used in cases where the preferred WordPress ‘WP_Image_Editor_Imagick’ class does not provide support for the requested mime-type or class method.

In some cases, the ImageMagick extension might not be installed, or might be unreliable (old versions of ImageMagick can be buggy). You can hook the WordPress ‘wp_image_editors’ filter to manage the preferred order of WordPress image classes.

For example, here’s a filter and function to remove the ImageMagick class altogether:

add_filter( 'wp_image_editors', 'select_wp_image_editors' );

/**
 * The default $editors value:
 * 
 *      array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' )
 */
function select_wp_image_editors( $editors ) {

        return array( 'WP_Image_Editor_GD' ); // only return WP_Image_Editor_GD
}

Or if you prefer to use GD first, you can re-order the editors array instead:

add_filter( 'wp_image_editors', 'select_wp_image_editors' );

function select_wp_image_editors( $editors ) {

        return array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
}
Find this content useful? Share it with your friends!