Imghdr: library that determines the type of image contained in a file or byte stream


This is my first pet rust project and it is a clone of the python’ imghdr module, which is trying to determine image type by its first bytes.

Small example would describe it better:

extern crate imghdr;

fn main() {
    match imghdr::open("/path/to/image.png") {
        Ok(imghdr::Type::Png) => println!("Yep, it is a png"),
        Ok(imghdr::Type::Jpg) => println!("Wow, it is a jpeg spy!"),
        _ => println!("Some other format or even not an image at all"),

It is not so big deal, I know, but can be useful sometimes :slight_smile: I’m still working on the additional image formats recognition and I would appreciate any feedback.

Links:, repository and documentation.


Exciting! Seems like there’s some overlap with the immeta crate.