Get image::ImageFormat from image::DynamicImage

Hi,

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.

Thanks

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

2 Likes

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

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.