I’m trying to add GIF generation functionality to my app so that the user can share their animated creations with their friends, etc.
In my app, the user can pick a static background image to have a item drop down onto, so the only moving part is the item.
I have the GIF generation working fine using this encoder which is based on this code, and the finished product looks the way I want it, but if the user chooses to have a background image, the file size goes over my target size of 3MB. Here is an example.
I also assume any tablet users would get huge files as well since the image size is the size of the view it’s generated from. All the GIFS are around 12-20 frames, so I’m guessing the issue is the number of colors, or that the colors of the background image are changing slightly from frame to frame for some reason.
So is there any way I can get the filesize consistently below 3MB, while maintaining the FPS and dimensions? (Altering the GIF generation code/Changing the colors of the background image/etc) Or if not, what would be the best way to get it below 3MB and still attract users?
Thanks in advance! (:
EDIT:
It looks like the problem is that the class I’m using doesn’t optimize each frame as a diff or delta of the last. Any suggestions? (:
Make sure that only the first frame contains the full image. Subsequent frames should only contain the differences to the previous frame. This should turn a large part of the frame transparent, which can be compressed much more efficiently by GIF.
Do the following test: if you double the framerate – does the file size double? If so, you currently don’t encode deltas only.
Also understand that GIF isn’t appropriate for photos, and will produce huge files or a really bad image quality.
Edit: So you might need to improve your image-generating code so that it only feeds the changed parts of the image to the encoder!