4

I was taking a backup of my wp-content folder. But when I noticed size of uploads folder. I was astonished and each image used in my blog had 5 copies with different sizes in that folder. All these totaled to 7GB in 2 months. This way it won't take long to fill a server storage. I have a lot of image gallery posts. I didn't knew this that each image in wordpress is resized and kept in different sizes and thought only featured images went through resizing.

So, is there a way that wordpress only resizes featured images?

7
  • 3
    Wholeheartedly agree. This has come up on WPA before and Otta wrote a plugin to deal with it. wordpress.org/plugins/dynamic-image-resizer Should be core imo. Generates only the sizes you need, when you need them. Jul 14, 2013 at 14:04
  • If you just want to create custom sizes on demand and on the fly, then I have written the "Dynamic Image Resize" plugin for that. It's slightly different from Otto/@helgatheviking solution. For more info take a look at the plugins dedicated page. Please note that the dedicated page at the current time isn't completely finished. In other words, the nav still got problems and styles aren't applied.
    – kaiser
    Jul 14, 2013 at 16:48
  • @helgatheviking, that's what I am talking about!
    – busyjax
    Jul 14, 2013 at 17:21
  • 1
    @helgatheviking Yes, exactly. You simply take any URL or attachment ID and it resizes the image to your desired size. Ottos plugin deactivates all build in size generation and then generates and serves images when they're requested. The drawback of Ottos method is that it only works with pretty permalinks and not on multisite. The "drawback" on mine is that it wasn't build for deactivating image size generation, but to generate custom sizes on the fly.
    – kaiser
    Jul 15, 2013 at 2:58
  • 1
    @kaiser Thanks for the explanation! It is brilliant that there are 2 viable solutions out there for this. Jul 15, 2013 at 4:14

1 Answer 1

3

You can simply set all unused image size attributes to 0 to stop WordPress generating them. Whilst this only applies for default image sizes, you can use filters to remove them.

In general, WP stores all those sizes to generate images for in the global $_wp_additional_image_sizes. The following plugin uses a filter to remove sizes on the fly. See the debugging points to unset/export/etc. the different sizes. You'll quickly get an overview and be able to remove what you don't need.

<?php
defined( 'ABSPATH' ) or exit;
/* Plugin Name: Disable Image Sizes */

add_filter( 'intermediate_image_sizes_advanced', 'wpse_106463_filter_image_sizes' );
function wpse_106463_filter_image_sizes( $sizes )
{
    // Uncomment the following line to see your image sizes:
    # printf( '<pre>%s</pre>', htmlspecialchars( var_export( $GLOBALS['_wp_additional_image_sizes'], true ) ) );

    // Unset default image sizes: Simply uncomment the line
    # unset( $sizes['thumbnail'] );
    # unset( $sizes['medium'] );
    # unset( $sizes['large'] );

    return $sizes;
}

And to add custom sizes to your Size selector in the admin UI, simply use the following:

add_filter( 'image_size_names_choose', 'wpse_106463_image_size_select' );
function wpse_106463_image_size_select( $sizes )
{
       return $sizes + array(
              'custom_size_name' => 'Avatar Size',
              'full'             => 'Original size'
       );
}
5
  • This won't select unused image files. This is a manual operation, isn't it?
    – JMau
    Jul 14, 2013 at 14:05
  • Actually, I have sidebar which shows popular, random and latest posts and single post page has related posts. These show featured image of the post. So, I need to resize featured image only.
    – busyjax
    Jul 14, 2013 at 14:17
  • @JMa It wasn't about selecting unused images - that's a completely different task. This is about deactivating the future generation of images that aren't used. The second function is about adding the needed custom sizes to the select option when inserting them into a posts content.
    – kaiser
    Jul 14, 2013 at 16:42
  • @busyjax Then deactivate all the sizes you don't need with above plugin. I can't write you a complete tutorial in here, but it gave you all the tools you need.
    – kaiser
    Jul 14, 2013 at 16:44
  • 1
    @kaiser ok thanks. I'm pretty interessed in this solution for one of my free plugins.
    – JMau
    Jul 14, 2013 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.