imsz
Get width and height from an image file reading as few bytes as possible.
This is a fork of scardine/imsz that adds support for more file formats, but also breaks API compatibility in order to be more idiomatic Rust. It also provides a C library wrapper. For more information on how this started see the mentioned link.
The library itself has zero dependencies, but the example binary uses clap.
Usage
There is a simple example binary:
<FILES>...
The relevant parts:
use imsz;
let info = imsz?;
println!;
// testdata/image.gif: GIF, 32 x 16
// or for already opened files:
let info = imsz;
// or for in memory buffers:
let info = imsz;
// or for *anything* implementing Read and Seek:
use imsz_from_reader;
let mut file = new;
let info = imsz_from_reader?;
Supported File Formats
- AVIF
- BMP
- DDS
- DIB
- GIF
- HEIC/HEIF
- ICO
- JPEG
- JPEG 2000
- PCX
- PNG
- PSD
- OpenEXR
- QOI
- TGA
- TIFF
- VTF
- WEBP
- XCF
No guarantees of correct or complete implementation are made.
Related Work
- scardine/imsz – original Rust library from which this is a fork
- panzi/get_image_size.py – a very similar library in pure Python
- StackOverflow answer – the start of it all