#image #size

imagesize

Quick probing of image dimensions without loading the entire file

18 unstable releases (7 breaking)

0.8.0 Mar 30, 2019
0.6.0 Nov 16, 2018
0.5.1 Feb 18, 2018
0.5.0 Sep 25, 2017
0.3.5 May 17, 2017

#24 in Images

Download history 209/week @ 2018-12-20 9/week @ 2018-12-27 82/week @ 2019-01-03 62/week @ 2019-01-10 25/week @ 2019-01-17 34/week @ 2019-01-24 98/week @ 2019-01-31 163/week @ 2019-02-07 40/week @ 2019-02-14 33/week @ 2019-02-21 79/week @ 2019-02-28 273/week @ 2019-03-07 229/week @ 2019-03-14 345/week @ 2019-03-21 67/week @ 2019-03-28

511 downloads per month
Used in 3 crates (2 directly)

MIT license

19KB
361 lines

ci-badge docs-badge crates.io version

imagesize

Quickly probe the size of various image formats without reading the entire file.

Usage

Add the following to your Cargo.toml:

[dependencies]
imagesize = "0.8"

Supported Image Formats

  • BMP
  • GIF
  • JPEG
  • PNG
  • PSD / PSB
  • TIFF
  • WEBP

Examples

From a file

let (width, height) = match size("example.webp") {
    Ok(dim) => (dim.width, dim.height),
    Err(why) => println!("Error getting dimensions: {:?}", why)
}

From a vector

Where magic_partial_download is a function that downloads a specified amount of bytes from a given url.

let data: Vec<u8> = magic_partial_download("http://example.com/example.jpg", 0x200);
let (width, height) = match blob_size(&data) {
    Ok(dim) => (dim.width, dim.height),
    Err(why) => println!("Error getting dimensions: {:?}", why)
}

No runtime deps