TotallyNotChase / glitch-this

:camera: Glitchify images and GIF - with highly customizable options!
MIT License
1.76k stars 63 forks source link

Unreasonably large gif size #41

Closed arxitim closed 2 years ago

arxitim commented 2 years ago

Hello!

I really like this library, and I even wanted to do glithed-background on my web-services, or just send to friends, but as soon as I pressed send, I was very surprised

It turns out that the size of the generated gif exceeds the size of the original photo in ascending order! That is, if the original image takes 100Kb, the gif will take 6.4Mb This is still not too much, but as soon as you try to make a gif from a 400Kb image, the output will be 39.8Mb!

Is there any way to optimize the size of the output file, or maybe there is some combination of flags that will reduce the size of the output gif?

I used the command to generate it:

glitch_this kanagawa.jpg 5 -g -c
TotallyNotChase commented 2 years ago

You could try reducing the number of frames - but this is unfortunately a natural downside to how PIL and gifs work in general - It's not very efficient. It could potentially be reduced further by tweaking the compression level in the library - but I've noticed that setting the compression level any lower makes the results look terrible.

The best solution might be to reduce your original image's resolution through an external tool - or reduce the output GIF's resolution through a similar method.

arxitim commented 2 years ago

I have made several unsuccessful attempts to optimize, and concluded that the problem is really at the lower levels.

But I noticed an interesting feature: the size of the output gif depends very much on the complexity of the original image. That is, a simple black square converted into a small gif, but the photo of landscape with lots of details incredibly increased in size, which confirms your words about the specifics of PIL and gif

Since this problem is completely unrelated to this particular library, I'll close the issue

Thank you!