WordPress Regenerate Thumbnails issue & PHP GD Library

WordPress Regenerate Thumbnails issue & PHP GD Library

Published: 5/23/2018

If you're familiar with WordPress you'll know that you can create different image sizes for all of your images on your website / blog and regenerate all the thumbnail sizes you'll need with plugins such as Regenerate Thumbnails (keep old unused image sizes) and Force Regenerate Thumbnails (remove all unused image sizes).

Pretty old news for WordPress developers I know, but what I came across recently, had me stumped for a good 30 minutes or so. Which is where a quick post about a problem might save someone else 30 minutes!

The problem occurred when using these plugins on a staging server that did not have the PHP GD library installed. Unfortunately, the regenerate thumbnails plugin does not produce an error - in fact it's quite the opposite. The images are regenerated blazingly fast!

At first I figured that perhaps the problem lay in file and folder permissions within the wp-content/uploads directory. But after playing around with this for several minutes and doing some testing, it turns out that the 0.216 seconds isn't the result of a ferrari-esque server or incorrect permissions - it simply skips the file with a success message.

Img

Img

Comparing my local environment to the staging is always a little tricky, but thankfully a little voice in the back of my head took a guess at the solution as being either ImageMagik or GD - both of which I had to install manually when I set up my local environment.

A quick and easy way to check if you have this problem is to spit out a yes/no for a check on whether this extension is installed. If you paste the following into your functions.php you should be able to see an HTML comment near the bottom of your website source-code with a clear message as to whether or not your GD library is installed.

function check_if_gd_installed() {
    if (!extension_loaded('gd')) {
        echo "<!-- GD library not installed -->";
    } else {
        echo "<!-- GD Library installed -->";
    }
}
add_action( 'wp_footer', 'check_if_gd_installed' );

One you've installed the library and tested - remove this script and get on with regenerating those thumbnails!