img
imghdr
cargo install imghdr
img

imghdr

Library that determines the type of image contained in a file or byte stream

by svartalf

0.7.0 (see all)License:Apache-2.0 OR MIT
cargo install imghdr
Readme

imghdr

Library that determines the type of image contained in a file or byte stream, basically clone of the Python imghdr module.

Latest Version Latest Version Rustc Version 1.31+ Travis Build Status Apache 2.0 OR MIT licensed

Examples

Check the file directly:

# extern crate imghdr;
# fn main() {
match imghdr::from_file("./tests/images/example.png") {
    Ok(Some(imghdr::Type::Png)) => println!("Yep, it is a PNG"),
    Ok(..) => println!("Nope, it is definitely not a PNG"),
    Err(e) => println!("Some error happened: {:?}", e),
}
# }

Or check the bytes stream:

# extern crate imghdr;
# use std::fs::File;
# use std::io::{self, Read};
#
# fn main() -> io::Result<()> {
let mut file = File::open("./tests/images/example.jpeg")?;
let mut content: Vec<u8> = vec![];
file.read_to_end(&mut content)?;

match imghdr::from_bytes(&content) {
    Some(imghdr::Type::Jpeg) => println!("And this is a Jpeg"),
    _ => println!("Can a Png, Bmp or other file format"),
}

# Ok(())
# }

GitHub Stars

11

LAST COMMIT

3yrs ago

MAINTAINERS

1

CONTRIBUTORS

2

OPEN ISSUES

0

OPEN PRs

1
VersionTagPublished
0.7.0
3yrs ago
0.6.0
3yrs ago
0.5.0
3yrs ago
0.4.0
6yrs ago
No alternatives found
No tutorials found
Add a tutorial