This is a fork of the imagesize crate. The git repository is located at https://github.com/Roughsketch/imagesize.
ai-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.
Features
- Fast: Reads only the necessary bytes to determine image dimensions
- Lightweight: Minimal dependencies
- Texture Format Support: Detects compression algorithms in DDS, PowerVR, PKM, and other texture containers
- Cross-Container Queries: Helper methods to identify compression families across different container formats
- Backward Compatible: All existing APIs remain unchanged
Usage
Add the following to your Cargo.toml:
[]
= "0.14"
Supported Image Formats
Simple Image Formats
- Aseprite
- Avif
- BMP
- EXR
- Farbfeld
- GIF
- HDR
- HEIC / HEIF
- ICO*
- ILBM (IFF)
- JPEG
- JPEG XL
- PNG
- PNM (PBM, PGM, PPM)
- PSD / PSB
- QOI
- TGA
- TIFF
- VTF
- WEBP
Texture Container Formats with Compression Detection
- DDS - DirectDraw Surface with BC1-7 (DXT1-5) compression detection
- PKM - ETC1/ETC2/EAC compressed textures
- PowerVR - PVRTC, ETC2, and EAC compressed textures
- ATC - Adaptive Texture Compression (Qualcomm Adreno)
- ASTC - Adaptive Scalable Texture Compression
- KTX2 - Khronos Texture Container
If you have a format you think should be added, feel free to create an issue.
*ICO files can contain multiple images, ai-imagesize will give the dimensions of the largest one.
Examples
From a file
match size
From a vector
let data = vec!;
match blob_size
Texture Format Detection
For texture container formats, you can detect both the container type and compression algorithm:
use ;
let data = read.unwrap;
match image_type
Cross-Container Compression Queries
Use helper methods to query compression information across different container formats:
use ;
let data = read.unwrap;
if let Ok = image_type