Function imagesize::get_dimensions_safe [] [src]

pub fn get_dimensions_safe<P>(path: P) -> ImageResult<Dimensions> where
    P: AsRef<Path>, 

Get the image dimensions from a local file with extra checks to ensure it's a valid image.

Arguments

  • path - A local path to the file to parse.

Remarks

This method is the safe version of get_dimensions. It is similar in that it will try to read as little of the file as possible in order to get the proper size information, but it also adds extra checks to ensure it is reading a valid image file.

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_safe;

match get_dimensions_safe("test/test.webp") {
    Ok(dim) => {
        assert_eq!(dim.width, 716);
        assert_eq!(dim.height, 716);
    }
    Err(why) => println!("Error getting dimensions: {:?}", why)
}