pub fn blob_size(data: &[u8]) -> ImageResult<ImageSize>
Expand description
Get the image size from a block of raw data.
§Arguments
data
- A Vec containing the data to parse for image size.
§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::blob_size;
// First few bytes of arbitrary data.
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!(blob_size(&data).is_err(), true);