Crates.io | imageformat |
lib.rs | imageformat |
version | |
source | src |
created_at | 2024-12-06 04:23:03.226496 |
updated_at | 2024-12-09 02:08:48.489428 |
description | Quick probing of image format without loading the entire file. |
homepage | https://github.com/AllenDang/imageformat |
repository | https://github.com/AllenDang/imageformat |
max_upload_size | |
id | 1473919 |
Cargo.toml error: | TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Quickly probe the format of various image formats without reading the entire file.
The goal of this crate is to be able to detect format of a supported image without loading unnecessary data, and without pulling in more dependencies. Most reads only require 16 bytes or less.
use image_format_detector::prelude::*;
fn main() {
// Example: Read the first few bytes of a file
let file = std::fs::File::open("/Somepath/example.webp")?;
let mut cursor = std::io::Cursor::new(file);
let format = detect_image_format(&mut cursor);
// Or: pass in the file path
let format = detect_image_format_path("/Somepath/example.png").unwrap();
match format {
ImageFormat::Jpeg => println!("It's a JPEG image."),
ImageFormat::JpegXl => println!("It's a JPEG XL image."),
ImageFormat::Png => println!("It's a PNG image."),
ImageFormat::Webp => println!("It's a WEBP image."),
...
}
}
If you have a format you think should be added, feel free to create an issue.