Filter what image sizes get generated

I’m looking for a way to chose what images sizes get generated by image. With all the image sizes I have plus a lot of images, in the end I have a whole lot of server space being used up for nothing.

Is there a way to either?

  • at upload, select what image sizes get generated for a specific image
  • after upload, go to the media page and check off certain image sizes

Related posts

Leave a Reply

2 comments

  1. Picking which image sizes to generate on a per-upload basis is definitely going to be a bit involved. However, if you’re okay with just entirely removing default image sizes, you have a couple of options, as described in this article:

    The simplest way is to set the default image height and width to ‘0’ at Settings > Media

    The only problem with that solution is that those sizes will still appear in the wordpress media uploader.

    To prevent those sizes from being generated and remove them from the media uploader, you can place the following code in your functions.php file (also grabbed from the article, I haven’t tested this code.):
    UPDATE: I tested this code in WP 3.5.1 and it works perfectly

    /**
     * Remove standard image sizes so that these sizes are not
     * created during the Media Upload process
     *
     * Tested with WP 3.2.1
     *
     * Hooked to intermediate_image_sizes_advanced filter
     * See wp_generate_attachment_metadata( $attachment_id, $file ) in wp-admin/includes/image.php
     *
     * @param $sizes, array of default and added image sizes
     * @return $sizes, modified array of image sizes
     * @author Ade Walker http://www.studiograsshopper.ch
     */
     function sgr_filter_image_sizes( $sizes) {
    
    unset( $sizes['thumbnail']);
    unset( $sizes['medium']);
    unset( $sizes['large']);
    
    return $sizes;
    }
    add_filter('intermediate_image_sizes_advanced', 'sgr_filter_image_sizes');