Fresco - How to check if a file is animated webP or not progrmmatically?

659 Views Asked by At

I have an image file of webP format. How can I check if it is animated webP or a static image programmatically?

2

There are 2 best solutions below

0
defhlt On

Since you added fresco tag to the question, you could use the following utility:

ImageFormatChecker.getImageFormat_WrapIOException(encodedImage.getInputStream()) should return ImageFormat.WEBP_ANIMATED

https://github.com/facebook/fresco/blob/master/imagepipeline-base/src/main/java/com/facebook/imageformat/DefaultImageFormatChecker.java#L125

0
CrackerKSR On

Here are some methods to get formats. Good thing is it identifies animation in webp. (mimeType and extention are same for animated and static type of webp, png, avif images)

InputStream is = ... ;
ImageFormat format = ImageFormatChecker.getImageFormat(is);

or

String uri = ... ;
ImageFormat format = ImageFormatChecker.getImageFormat(uri);

or

InputStream is = ... ;
ImageFormat format = ImageFormatChecker.getImageFormat_WrapIOException(is);

Used Fresco version : 3.1.3.