set_post_thumbnail_size( 80, 80, true ); // true for all post types

Suppose I have two post types in play on my blog: Post, Video and Product. I may want a 80×80 image size for my posts, but 100×100 for my videos and a 50×100 for my Products. To my knowledge, I am forced to create thumbnails for my Post images in the dimensions of 100×100 and also 50×100. And for my products, I’m forced to create thumbnails that are 80×80 and 100×100, even though I won’t use those ever.

Is there a way to create image sizes that are based on post types so you don’t end up making a bunch of images you don’t plan on using, and wasting resources that could be used elsewhere?

3

There is no way to base the image sizes on the post type, as images are not yet attached to a post when you upload them and the intermediate image sizes are created (when you just add them via “New Media” they are not even attached to any post at all).

However, I recently created two plugins that together will do what you want. Virtual intermediate images will intercept the creation of the intermediate image sizes: they will not be created on disk, but still exist in the metadata array. This makes WordPress think they exist so you can use them like normal images. The companion plugin, On-Demand Resizer will create missing image sizes when they are requested. The first time the image is requested it is created, all subsequent requests will just be served the newly created image.

These plugins need a rewrite before I put them in the WordPress plugin directory, but they should be safe. Or at least have TODO comments where they are unsafe.

Leave a Reply

Your email address will not be published. Required fields are marked *