WordPress not creating images

ivarrafn wrote this on Feb 06, 2015


Why is WordPress not generating Image thumbnails that are specifically set using add_image_size()

I've had this problem before and it just happened again today.

I was importing posts from another WordPress install and the image thumbnails were not being generated. I even tried uploading new images but still no thumbnails.

Themes and plugins can use a function called add_image_size()to register a new image size. For example we could include this in our theme:

add_image_size('medium-thumbnail', 160, 160)

That would tell WordPress that when the user uploads a new image WordPress should create a version of that image in the sizes that are inserted in the function, in this case a 160x160 pixel image.


Regenerate Thumbnail

My first thought was to install a plugin like Regenerate Thumbnail which enables you to run through all the images you have uploaded and regenerate the extra image sizes needed. This is very useful especially when you're importing posts from another site.

If you're having issues with image sizes when migrating from another theme I would try this plugin.

The Regenerate Thumbnails plugin seemed to run fine and it looked like all the images were resized and ready to go but after reloading the page, where the images were wrong, I saw it didn't work.


GD PHP extension

After a few minutes it hit me, WordPress uses a PHP extension called GD to manipulate images and since I was working on a new server setup I haven't installed it.

All I needed to do was run this via SSH:

apt-get install php5-gd

After restarting Apache I ran Regenerate Thumbnails again and it worked perfectly. Your hosting provider can help you enable this if you don't have SSH access to your server.

It's strange that WordPress doesn't notify you about this, it accepts the add_image_size function and when you upload an image it goes through it like everything is all right but in reality it fails silently to create the necessary thumbnails, all without notice.


How to check if GD is installed

Paste this PHP code in your functions.php file and reload the front page.

if(extension_loaded('gd') && function_exists('gd_info')){
    echo 'GD is installed!';
}else{
    echo 'GD is NOT installed!';
}
exit();

You should see a white page with text that says either that GD is installed or not.


I hope this helps.

If you've had image issues in WordPress that were caused by something else, please comment below and share your experience.


Share this post


About the author

Ivar Rafn is a web developer and co-founder of bluthemes. Bluthemes creates WordPress themes and sells them exclusively on ThemeForest.net. Check out the theme portfolio right here.

Subscribe to our newsletter

If you're interested in Web development, WordPress or would like to hear about our journey as a ThemeForest author insert your email below and get our latest content first!

The latest theme from Bluthemes

Bacon

User Generated Recipe Theme

Bacon is the perfect food & recipe theme for you! It allows you to post recipes as well as open recipe submission up for your users.


Leave a comment