| 1 | [![crates.io version]][crates.io link] [![docs-badge][]][docs] |
| 2 | |
| 3 | # imagesize |
| 4 | Quickly probe the size of various image formats without reading the entire file. |
| 5 | |
| 6 | 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. |
| 7 | |
| 8 | ## Usage |
| 9 | Add the following to your Cargo.toml: |
| 10 | ```toml |
| 11 | [dependencies] |
| 12 | imagesize = "0.13" |
| 13 | ``` |
| 14 | |
| 15 | ## Supported Image Formats |
| 16 | * Aseprite |
| 17 | * Avif |
| 18 | * BMP |
| 19 | * DDS |
| 20 | * EXR |
| 21 | * Farbfeld |
| 22 | * GIF |
| 23 | * HDR |
| 24 | * HEIC / HEIF |
| 25 | * ICO* |
| 26 | * ILBM (IFF) |
| 27 | * JPEG |
| 28 | * JPEG XL |
| 29 | * KTX2 |
| 30 | * PNG |
| 31 | * PNM (PBM, PGM, PPM) |
| 32 | * PSD / PSB |
| 33 | * QOI |
| 34 | * TGA |
| 35 | * TIFF |
| 36 | * VTF |
| 37 | * WEBP |
| 38 | |
| 39 | If you have a format you think should be added, feel free to create an issue. |
| 40 | |
| 41 | *ICO files can contain multiple images, `imagesize` will give the dimensions of the largest one. |
| 42 | |
| 43 | ## Examples |
| 44 | |
| 45 | ### From a file |
| 46 | ```rust |
| 47 | match imagesize::size("example.webp") { |
| 48 | Ok(size) => println!("Image dimensions: {}x{}", size.width, size.height), |
| 49 | Err(why) => println!("Error getting dimensions: {:?}", why) |
| 50 | } |
| 51 | ``` |
| 52 | |
| 53 | ### From a vector |
| 54 | ```rust |
| 55 | let data = vec![0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x64, 0x00, 0x64, 0x00]; |
| 56 | match imagesize::blob_size(&data) { |
| 57 | Ok(size) => println!("Image dimensions: {}x{}", size.width, size.height), |
| 58 | Err(why) => println!("Error getting dimensions: {:?}", why), |
| 59 | } |
| 60 | ``` |
| 61 | |
| 62 | [crates.io link]: https://crates.io/crates/imagesize |
| 63 | [crates.io version]: https://img.shields.io/crates/v/imagesize.svg?style=flat-square |
| 64 | [docs]: https://docs.rs/imagesize |
| 65 | [docs-badge]: https://img.shields.io/badge/docs-online-5023dd.svg?style=flat-square |