javaandroidkotlingifwebp

How to resize GIF/Animated WebP image files in Android?


How can we resize the animated image files like gif, animated webp or animated png files in android ? I am not asking about showing animation on Image View. My goal is to save the animated image file on storage after resizing.

I tried glide but we have to write complex code to get bitmap of each frame and then fit that bitmap to specific size or crop it then encode all those frames back into an animated image file.

There is another lib called imagemagick but android version has some issue that i could not use it

APNG4ANDROID is another library which looks perfect for this operation but it has also some issues although its good lib for showing animated images. it is not meant for this resize stuff


Solution

  • Finally I found the solution after lots of searching and exxperimenting.

    For Gif:

    For Webp:

    (Delay is also available to use it with encoder)

    Gif encoder decoder https://github.com/waynejo/android-ndk-gif

    Webp Ecnoder https://github.com/b4rtaz/android-webp-encoder

    Webp decoding using Glide: https://stackoverflow.com/a/64744296/9308731

    Resizing: https://stackoverflow.com/a/32810187/9308731