apply_filters( ‘intermediate_image_sizes_advanced’, array $new_sizes, array $image_meta, int $attachment_id )

Filters the image sizes automatically generated when uploading an image.

Parameters

$new_sizesarray
Associative array of image sizes to be created.
$image_metaarray
The image meta data: width, height, file, sizes, etc.
$attachment_idint
The attachment post ID for the image.

Source

$new_sizes = apply_filters( 'intermediate_image_sizes_advanced', $new_sizes, $image_meta, $attachment_id );

Changelog

VersionDescription
5.3.0Added the $attachment_id argument.
4.4.0Added the $image_meta argument.
2.9.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    You can exclude certain image types from images sizes, like gifs

    function wpdocs_disable_upload_sizes( $sizes, $image_meta ) {
    
        // Get filetype data.
        $filetype = wp_check_filetype( $image_meta['file'] );
    	
        $exclude_file_types = array(
        	'image/gif',
        );
    
        // Check if file type is on exclude list 
        if ( in_array( $filetype['type'], $exclude_file_types ) ) {
            $sizes = array();
        }
    
        // Return sizes you want to create from image (None if image is gif.)
        return $sizes;
    }   
    add_filter( 'intermediate_image_sizes_advanced', 'wpdocs_disable_upload_sizes', 10, 2 );

You must log in before being able to contribute a note or feedback.