What Are Imagick and GD?
Imagick and GD are popular image optimization libraries in PHP applications. While they both perform many of the same actions, they operate a bit different from each other and offer different benefits.
Overall, these two libraries are used for:
- Resizing/cropping images.
- Modifying the contents of an image.
- Image compression.
- Conversion to different file types.
- Applying image filters such as adjusting contrast, brightness, colors, etc.
Are Both Imagick and GD Available?
All Pagely servers come with both GD and Imagick modules available. As of version 3.5.0, WordPress will default to using Imagick. If Imagick is not available or is unable to process the image, GD will be used instead.
For more information, see the WordPress media.php source.
Which Should I Use?
In most cases, it doesn't really matter much. Both libraries support the majority of common file types and perform similarly in a typical WordPress environment. However, if you have an extremely image-heavy site or are dealing with more obscure image file formats, you might want to make a deeper decision based on your particular needs.
Generally speaking, the differences are:
- GD is generally a slight bit faster when dealing with large images.
- Imagick supports a larger number of image formats.
- Imagick is usually better at producing higher quality images (although sometimes at the expense of file size).
What If I Want to Use GD By Default?
Since it's statically defined in the WordPress core file, modifying the image editor must be done using an add_filter
step inside of each WordPress application at Pagely.
Here's an example drop-in plugin to default to GD:
<?php
/**
* Plugin Name: Use GD For Image Processing
* Plugin URI: https://support.pagely.com/hc/en-us/articles/115000052451
* Description: Sets GD to the default image processor.
* Version: 1.0.0
* Requires at least: 5.5
* Requires PHP: 7.2
* Author: JeffMatson, Pagely
* Author URI: https://pagely.com
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
add_filter( 'wp_image_editors', 'pagely_default_to_gd' );
function pagely_default_to_gd() {
return array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
}
Note: Pagely's policy is to provide a 'vanilla' WordPress core. We do not modify any code that is distributed as part of the default software. We recommend using the facilities provided in WordPress to modify the application's behavior as needed.