imagesize
Quickly probe the size of various image formats without reading the entire file.
Usage
Add the following to your Cargo.toml:
[]
= "0.3"
And import it using extern crate
:
extern crate imagesize;
Supported Image Formats
- BMP
- GIF
- JPEG
- PNG
- WEBP
Examples
Note about *_safe
Both functions shown below have an accompanying safe version, i.e. get_dimensions_safe
and get_dimensions_from_blob_safe
. The safe variants have added checks to be more certain an image is a file before returning a size. The non-safe versions will only check the first byte of the file which can be dangerous for formats which have ASCII character magic numbers.
From a file
let = match get_dimensions
From a vector
Where magic_partial_download
is a function that downloads a specified amount of bytes from a given url.
let data: = magic_partial_download;
let = match get_dimensions_from_blob