-2

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).

Nimantha
  • 5,793
  • 5
  • 23
  • 56
CrackerKSR
  • 710
  • 7
  • 19
  • If size of the apk doesn't matter for you, you can use ffmpeg – Dima Rostopira Mar 05 '22 at 12:21
  • Thanks for comment. Yeah I could use that but I tried ffmpeg in React Native and achive the goal with gif files but cannot resize the animated webp file. I came to know that it does not have animated webp decoder so it can only resize the gif and encode to animated webp. – CrackerKSR Mar 05 '22 at 12:27
  • 1
    I'm voting to close this question. Asking for "suggestions" makes it seem like you are asking for a library which is off-topic for SO. I suggest you either add more details, what have you tried, why did that not work etc, if this is really a *programming question*. Or, ask for a library on [Software Recommendations SE](https://softwarerecs.stackexchange.com). – Harald K Mar 07 '22 at 13:53
  • Found this question, it looks like it's possible: https://stackoverflow.com/questions/53024304 – Dima Rostopira Mar 29 '22 at 09:00

1 Answers1

0

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

CrackerKSR
  • 710
  • 7
  • 19