Function imagesize::size

source ·
pub fn size<P: AsRef<Path>>(path: P) -> ImageResult<ImageSize>
Expand description

Get the image size from a local file

Arguments

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

Remarks

Will try to read as little of the file as possible in order to get the proper size information.

Error

This method will return an ImageError under the following conditions:

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

The minimum data required is 12 bytes. Anything shorter will return ImageError::IoError.

Examples

use imagesize::size;

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