Crates.io | imagesize |
lib.rs | imagesize |
version | 0.13.0 |
source | src |
created_at | 2017-05-01 01:28:19.676408 |
updated_at | 2024-06-18 02:24:29.342152 |
description | Quick probing of image dimensions without loading the entire file. |
homepage | |
repository | https://github.com/Roughsketch/imagesize |
max_upload_size | |
id | 12600 |
size | 60,901 |
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.
Add the following to your Cargo.toml:
[dependencies]
imagesize = "0.13"
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.
match imagesize::size("example.webp") {
Ok(size) => println!("Image dimensions: {}x{}", size.width, size.height),
Err(why) => println!("Error getting dimensions: {:?}", why)
}
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),
}