#image #size

imagesize

Quick probing of image dimensions without loading the entire file

14 releases

0.5.2 Aug 15, 2018
0.5.1 Feb 18, 2018
0.5.0 Sep 25, 2017
0.4.0 Sep 24, 2017
0.1.2 May 1, 2017

#22 in Images

Download history 22/week @ 2018-07-21 30/week @ 2018-07-28 70/week @ 2018-08-04 121/week @ 2018-08-11 50/week @ 2018-08-18 44/week @ 2018-08-25 32/week @ 2018-09-01 17/week @ 2018-09-08 15/week @ 2018-09-15 11/week @ 2018-09-22 66/week @ 2018-09-29 40/week @ 2018-10-06 59/week @ 2018-10-13

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

MIT license

13KB
236 lines

ci-badge docs-badge

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.5"

And import it using extern crate:

extern crate imagesize;

Supported Image Formats

  • BMP
  • GIF
  • JPEG
  • PNG
  • 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