imagesize 0.8.7

Quick probing of image dimensions without loading the entire file.
Documentation

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)
}