Function imagesize::get_dimensions_from_blob_safe [] [src]

pub fn get_dimensions_from_blob_safe(data: &Vec<u8>) -> ImageResult<Dimensions>

Get the image dimensions from a block of data with extra checks to ensure it's a valid image.

Arguments

  • data - A Vec containing the data to parse for image dimensions.

Remarks

This method is the same as get_dimensions_from_blob, except it has added checks to make sure that the given data is in fact an image.

Error

This method will return an ImageError under the following conditions:

  • The header isn't recognized as a supported image
  • The data isn't long enough to find the dimensions for the given format

Examples

use imagesize::get_dimensions_from_blob_safe;

// First few bytes of arbitrary data.
// get_dimensions_from_blob would assume this is a PNG with size 123x16777537
let data = vec![0x89, 0x89, 0x89, 0x89, 0x0D, 0x0A, 0x1A, 0x0A, 
                0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 
                0x00, 0x00, 0x00, 0x7B, 0x01, 0x00, 0x01, 0x41,
                0x08, 0x06, 0x00, 0x00, 0x00, 0x9A, 0x38, 0xC4];

assert_eq!(get_dimensions_from_blob_safe(&data).is_err(), true);