Get image::ImageFormat from image::DynamicImage


I'm new to Rust. I have a method that accepts an image::DynamicImage and I would like to get image::ImageFormat from it. Is it possible?

My requirement is to check the type of image passed into the method - whether it's png, jpeg etc.


Nope. The DynamicImage doesn't encode any format information - it is simply a rectangular matrix of pixels.


If you have to identify an image format, but don't have the direct method from the language, you can look at the image header and determine the type this way. As long as they are not corrupt, every format will have different header.

1 Like