Issue
I want to resize gif and animated webp files in Android.
There are few libraries I tried, like ffmpeg(not have animated webp encode), ImageMagick, Sharp but could not add in android project as they gives various errors apart from that those libs has more than enough functionality which would be there unnecessarily increasing the app size.
I tried kMagick, Glide as well but kmagick gives messed up output for animated gif (static images works fina) glide does not change the size rather it keeps the original file (but works fine for static images)
I asked the dev of kmagick and riase issue on glide.
PS: I have been experimenting with various libs to get the desired output. I tried, tested many libraries and then raise issue on their repo as well and if some method is from Stack Overflow answer or article I commented there as well. I am shocked to know that gif and webp animated image files resizing and convertion between them is so hard to Android developers that no single library is there to manipulate the gif webp easily like we do with static images. (net is full of manipulating the views of gif webp i.e. resize, fit, crop, flip, rotate).
Solution
Finally I found the solution after lots of searching and exxperimenting.
For Gif:
- Extract frames from gif using decoder
- Resize the each bitmaps.
- encode them into webp or gif using encoder
For Webp:
- (Need Glid) use given code to extract frames as bitmaps.
- Resize them
- encode into gif/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
Answered By - CrackerKSR
Answer Checked By - Timothy Miller (JavaFixing Admin)