Validate An Available Image Format In WordPress

Using the WordPress built-in function getintermediateimagesizes() or the global variable $wpadditionalimage_sizes to validate a specific image format in WordPress on a simple way:

function validate_image_size_first( $size_name )
{
    $available_image_sizes = get_intermediate_image_sizes();

    foreach ($available_image_sizes as $available_image_size)
    {
        if( $available_image_size === $size_name )
        {
            return true;
        }
    }

    return false;
}

validate_image_size_first('my-custom-image-format');

OR

function validate_image_size_second( $size_name )
{
    global $_wp_additional_image_sizes;

    if( isset($_wp_additional_image_sizes[$size_name]) )
    {
        return true;
    }

    return false;
}

validate_image_size_second('my-custom-image-format');
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn