#image-format #size #dimension #loading #file #probing #data

imagesize

Quick probing of image dimensions without loading the entire file

31 releases

0.12.0 May 11, 2023
0.11.0 Jan 6, 2023
0.10.1 Sep 24, 2022
0.10.0 Jul 15, 2022
0.3.5 May 17, 2017

#20 in Images

Download history 20330/week @ 2023-11-21 22179/week @ 2023-11-28 19411/week @ 2023-12-05 18545/week @ 2023-12-12 17619/week @ 2023-12-19 13685/week @ 2023-12-26 19410/week @ 2024-01-02 20826/week @ 2024-01-09 27995/week @ 2024-01-16 26433/week @ 2024-01-23 28833/week @ 2024-01-30 29698/week @ 2024-02-06 32231/week @ 2024-02-13 32200/week @ 2024-02-20 27633/week @ 2024-02-27 24478/week @ 2024-03-05

120,751 downloads per month
Used in 171 crates (21 directly)

MIT license

54KB
1K SLoC

crates.io version docs-badge

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

Supported Image Formats

  • Aseprite
  • BMP
  • DDS
  • EXR
  • Farbfeld
  • GIF
  • HDR
  • HEIC / HEIF
  • ICO*
  • JPEG
  • JPEG XL
  • KTX2
  • PNG
  • PNM (PBM, PGM, PPM)
  • PSD / PSB
  • QOI
  • TGA
  • TIFF
  • VTF
  • WEBP

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

*ICO files can contain multiple images, imagesize will give the dimensions of the largest one.

Examples

From a file

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

From a vector

let data = vec![0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x64, 0x00, 0x64, 0x00];
match imagesize::blob_size(&data) {
    Ok(size) => println!("Image dimensions: {}x{}", size.width, size.height),
    Err(why) => println!("Error getting dimensions: {:?}", why),
}

No runtime deps