#image-format #image #size #dimension #file #loading #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 19354/week @ 2023-12-18 13231/week @ 2023-12-25 17958/week @ 2024-01-01 20848/week @ 2024-01-08 25972/week @ 2024-01-15 27322/week @ 2024-01-22 28769/week @ 2024-01-29 30281/week @ 2024-02-05 30405/week @ 2024-02-12 33608/week @ 2024-02-19 28023/week @ 2024-02-26 28676/week @ 2024-03-04 30255/week @ 2024-03-11 32981/week @ 2024-03-18 32940/week @ 2024-03-25 30441/week @ 2024-04-01

129,143 downloads per month
Used in 197 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