Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/roughsketch/imagesize
Quickly probe the size of various image formats without reading the entire file.
https://github.com/roughsketch/imagesize
image image-analysis rust rust-library
Last synced: 8 days ago
JSON representation
Quickly probe the size of various image formats without reading the entire file.
- Host: GitHub
- URL: https://github.com/roughsketch/imagesize
- Owner: Roughsketch
- License: mit
- Created: 2017-05-01T01:11:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-14T23:59:46.000Z (over 1 year ago)
- Last Synced: 2024-04-28T09:05:30.717Z (6 months ago)
- Topics: image, image-analysis, rust, rust-library
- Language: Rust
- Size: 13.6 MB
- Stars: 55
- Watchers: 3
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![crates.io version]][crates.io link] [![docs-badge][]][docs]
# 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:
```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
* WEBPIf 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
```rust
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
```rust
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),
}
```[crates.io link]: https://crates.io/crates/imagesize
[crates.io version]: https://img.shields.io/crates/v/imagesize.svg?style=flat-square
[docs]: https://docs.rs/imagesize
[docs-badge]: https://img.shields.io/badge/docs-online-5023dd.svg?style=flat-square