#dimension #image-format #image #size #metadata #file-metadata #reading-file

imagesize

Quick probing of image dimensions without loading the entire file

32 releases

0.13.0 Jun 18, 2024
0.12.0 May 11, 2023
0.11.0 Jan 6, 2023
0.10.1 Sep 24, 2022
0.3.5 May 17, 2017

#14 in Images

Download history 29556/week @ 2024-04-03 28035/week @ 2024-04-10 33394/week @ 2024-04-17 31805/week @ 2024-04-24 32095/week @ 2024-05-01 35776/week @ 2024-05-08 40913/week @ 2024-05-15 39488/week @ 2024-05-22 30544/week @ 2024-05-29 39006/week @ 2024-06-05 50644/week @ 2024-06-12 51199/week @ 2024-06-19 50177/week @ 2024-06-26 45063/week @ 2024-07-03 49507/week @ 2024-07-10 41183/week @ 2024-07-17

195,527 downloads per month
Used in 228 crates (21 directly)

MIT license

58KB
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.13"

Supported Image Formats

  • Aseprite
  • Avif
  • BMP
  • DDS
  • EXR
  • Farbfeld
  • GIF
  • HDR
  • HEIC / HEIF
  • ICO*
  • ILBM (IFF)
  • 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