#image #size

imagesize

Quick probing of image dimensions without loading the entire file

22 releases

Uses old Rust 2015

0.8.4 Jul 30, 2020
0.8.1 Mar 15, 2020
0.8.0 Mar 30, 2019
0.6.0 Nov 16, 2018
0.3.5 May 17, 2017

#43 in Images

Download history 117/week @ 2020-04-17 279/week @ 2020-04-24 413/week @ 2020-05-01 287/week @ 2020-05-08 76/week @ 2020-05-15 95/week @ 2020-05-22 74/week @ 2020-05-29 111/week @ 2020-06-05 96/week @ 2020-06-12 34/week @ 2020-06-19 49/week @ 2020-06-26 75/week @ 2020-07-03 104/week @ 2020-07-10 43/week @ 2020-07-17 79/week @ 2020-07-24 94/week @ 2020-07-31

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

MIT license

24KB
463 lines

ci-badge docs-badge crates.io version

imagesize

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

The goal of this crate is to be able to read the dimensions of a supported image without loading unnecessary data, and without pulling in more dependencies. Most reads only require 16 bytes or less, and more complex formats take advantage of skipping junk data.

Usage

Add the following to your Cargo.toml:

[dependencies]
imagesize = "0.8"

Supported Image Formats

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

If you have a format you think should be added, feel free to create an issue.

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