#image #size

imagesize

Quick probing of image dimensions without loading the entire file

13 unstable releases (4 breaking)

0.5.1 Feb 18, 2018
0.5.0 Sep 25, 2017
0.4.0 Sep 24, 2017
0.3.5 May 17, 2017
0.1.2 May 1, 2017

#24 in Images

Download history 20/week @ 2018-05-04 15/week @ 2018-05-11 14/week @ 2018-05-18 47/week @ 2018-05-25 60/week @ 2018-06-01 13/week @ 2018-06-08 60/week @ 2018-06-15 24/week @ 2018-06-22 67/week @ 2018-06-29 7/week @ 2018-07-06 26/week @ 2018-07-13 48/week @ 2018-07-20 33/week @ 2018-07-27

163 downloads per month

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)
}
MIT license
  • No runtime deps

Reverse deps