WordPress Not Resizing Images and Generating Thumbnails: GD Library Not Installed

I write a weekly newsletter, sharing my articles and thoughts on building and running websites. There’s no spam and it’s totally free.
Join 1500+ subscribers!

How I realized That WordPress Was Not Resizing Images

Recently, I’ve installed WordPress on a new server.

After a couple of days, I realized that WordPress was not resizing images and creating image thumbnails. The images were used in their original size all over the website.

For example, I attached a 1920×1080 pixel image to a post as a featured image, in hopes that WordPress would create and use all the appropriate image sizes automatically.

But, to my surprise, that didn’t happen. When I looked at the source code of the pages generated by WordPress, the theme wasn’t using any other image/thumbnail sizes, but the original ones.

Then I checked the WordPress uploads directory, and only the original sizes of images where there.

Hence, it was clear to me that something was wrong.

In this article, you’ll learn what to do if you ever encounter a problem like this.

How to Check if WordPress Is Creating and Using Specified Sizes of Images and Thumbnails

There are three easy ways to check if WordPress is creating and using the appropriate image sizes and thumbnails.

1) Download Image to Your Computer

The first way to check the size of an image used by WordPress is to download the image to your computer.

Go to a page, where WordPress is supposed to use a resized image. For example, go to your blog home page, where all your posts are listed along with their respective thumbnails.

Right-click on a thumbnail and select Save image as.

Save Image As...
Save Image As…

Now, go to the folder where the image has been saved, and look at the image properties (or just hover your mouse cursor over the image). There, you should see the image dimensions.

If the image dimensions are those of the original image and not a thumbnail, then it means that WordPress is using the original image size, and not the resized thumbnail.

2) Page Source Code

The second way is to look at the source code of the pages generated by WordPress.

If WordPress is creating and using resized images, the image names will look something like image_150x150.jpg. In other words, the resized image size will be appended to the image name.

WordPress Page Source Code
WordPress Page Source Code

If the image size is not appended to the image name, WordPress is using the original image size.

3) Uploads Directory

The third way is to look at what’s in the WordPress uploads directory.

WordPress stores images in wp-content/uploads/year/month/ directory on your web server.

In that directory, there should be all the image sizes along with the original images.

For example, you should see files named like this:

image.jpg image-150x150.jpg image-300x300.jpg etc.

The resized images have their dimensions attached to their name.

Image Files in the Uploads Directory
Image Files in the Uploads Directory

If you don’t have images files like the examples above in your uploads directory, WordPress is not creating the resized images.

What’s Causing the Problem

I’ve seen other people having similar problems before. Typically, they were not able to generate custom image sizes and thumbnails with WordPress plugins like Regenerate Thumbnails and Simple Image Sizes or using the function add_image_size().

The reason was always the same. Missing PHP GD library.

GD Graphics Library
GD Graphics Library

GD is an open source library for creating and manipulating images by a program code.

If you don’t have GD installed on your web server, WordPress can’t resize, crop, or otherwise manipulate your images.

How to Check if GD PHP Extension Is Installed

There are several ways to check if GD PHP is installed. These are some of them.

1) phpinfo()

Create a plain text file, and name it phpinfo.php.

Put this line of code in it:

<?php phpinfo(); ?>

Upload the file the root directory of your website.

Then, in your web browser, go to http://example.com/phpinfo.php. Replace http://example.com with your domain name.

You should see the output of the phpinfo command. It will display all the information about php installed on your web server.

Look for the lines with the words GD, GD Support or GD version.

PHPINFO: GD
PHPINFO: GD

If GD PHP is installed, phpinfo will display its version and the information whether it’s enabled or not.

If you can’t see any mention of GD, it’s not installed on your web server.

2) extension_loaded(‘gd’)

Again, create a plain text file. Name it gd.php.

Copy this code to the file:

<?php 
if (extension_loaded('gd') && function_exists('gd_info')) 
{ 
  echo "GD is installed"; 
} 
else 
{ 
  echo "GD is not installed"; 
} 
?>

Upload the file to your website’s root directory.

In your web browser, go to http://example.com/gd.php. Replace http://example.com with your domain name.

If GD library is installed on your web server, you will see the message “GD is installed”.

Otherwise, GD is not installed on your web server.

3) PHP Code in a Widget

Install the Enhanced Text Widget WordPress plugin. It will add an Enhanced Text widget to your WordPress.

Unlike the standard text widget, the Enhanced Text widget allows you to use PHP in addition to regular text and HTML. You can type a piece of PHP code in the Enhanced Text widget, and it will be executed when WordPress generates the page that contains the widget.

Enhaced Text Widget
Enhanced Text Widget

Add the Enhanced Text widget somewhere on your website, and copy the following code into it. It’s the same code from the previous example.

<?php 
if (extension_loaded('gd') && function_exists('gd_info')) 
{ 
  echo "GD is installed"; 
} 
else 
{ 
  echo "GD is not installed"; 
} 
?>

This time, the result will be displayed by WordPress, wherever you placed the Enhanced Text widget.

4) Command Line

You can type one of the following commands on your web server’s command line to see if GD library is installed.

List all installed PHP modules:

php -m

Display all the PHP info (command line equivalent for the phpinfo() command):

php -i

Only display lines containing “GD”, if any:

php -i | grep 'GD'
php -i | grep 'GD'
php -i | grep ‘GD’

How to Install the PHP GD Extension

If you found out that the GD PHP extension was not installed on your web server, install the GD package.

To install PHP GD library, use the following command:

sudo apt-get install php7.0-gd

If you are using PHP 5:

sudo apt-get install php5-gd

Restart Apache

After the PHP GD library installation, you need to restart the Apache web server:

sudo service apache2 restart

Regenerate Thumbnails

Now that the PHP GD library is installed on your web server, WordPress will create all the required sizes of images you upload from now on.

But the images you uploaded before you installed GD will remain unchanged.

Luckily, there is a plugin called Regenerate Thumbnails. Use this plugin to create all the image dimensions required by your theme and any other custom image sizes.

Regenerate Thumbnails
Regenerate Thumbnails

After you’ve installed the plugin, go to Tools->Regen. Thumbnails. Click on the Regenerate All Thumbnails button. The plugin will generate all the required image sizes from images uploaded before GD was installed.

Conclusion

If your WordPress is not creating the required image sizes and is only using the original image size all over your website, the most probable reason is that you don’t have GD PHP library installed.

You need to install the PHP GD extension on your web server.

After installing the PHP GD extension, restart the Apache web server.

Finally, use the Regenerate Thumbnails WordPress plugin to create all the required image sizes.

I write a weekly newsletter, sharing my articles and thoughts on building and running websites. There’s no spam and it’s totally free. Join 1500+ subscribers!