-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compressed GIF is larger than Original #154
Comments
Any ideas @denji ? @kohler ? @kornelski ? |
First, if you're resizing, it's very common for resized GIF to take much more space than the original. Resizing adds more soft edges and more colors, which are two worst things for the GIF compression. Lossy works well on GIFs that are video-like, with lots of similar colors and gradients. If your GIF is simple with hard edges, then there's nothing to gain from lossy. I don't think there's much to be done about this. Don't assume recompression will always make images smaller. Keep the original image if the original is smaller. Also, if you have GIFs that are MB in size, and care about file sizes, then don't use GIF. Convert them to MP4 or AV1 (APNG and AWebP are "meh", and may be larger in some cases too). Safari can even play MP4 directly from |
Thank you for your comments. The system doesn't know anything about the GIF, since it's anything that the user uploads. Resizing is important, so the images don't cross the maximum width/height. Note that the biggest factor for increasing the file size was the "lossy" option. I appreciate the suggestion of converting to movie. That seems to be more work, so have to put in the backlog for now :) Have a good day. |
Just to note, though, The problem is more the "optimizations": $ /usr/local/bin/gifsicle -O3 -Okeep-empty --no-extensions Original.gif -o Compressed5.gif $ ls -l Asking to optimize, with either -O1, -O2 or -O3, the file size increases. This does happen to a number of GIF images. |
It increases even without lossy? You must have a pretty well-compressed GIF to begin with. |
Yes, that's what my examples above were saying. --lossy has the biggest impact on causing the file to increase the most. Without it, the file still increases. Even this simple command: $ /usr/local/bin/gifsicle Original.gif -o Compressed6.gif The file increases. I wish there was a way to 100% turn off optimizations. For example, I may want to ONLY resize the GIF file (as that's the requirement). THEN, I want to try optimizations, and see if the file reduced. If didn't, then I discard the optimization. However, the way it works now, if I try to use the "resize-fit" option without any other options, gifsicle will default to -O1 (I think?), which can increase the file size. |
Technically there doesn't exist such thing as resizing images. Resizing is done by generating a brand new image with new pixels and new compression. It's not modifying the old file to somehow make it have a different size. There is no way around that in raster formats like GIF (apart from an uninteresting case where you request resizing to the same size, so there's no resizing to do). Compression and pixel dimensions are absolutely inseparable, so making new image size always requires making a new file with new compression done from scratch. |
Thank you. I understand. But see this: $ /usr/local/bin/gifsicle --resize-fit 720x720 Original.gif -o Compressed6.gif The image is smaller than 720x720, so it should not resize at all (and does not, but the file size increases). What else is gifsicle doing, that causes the file size to increase from 1010151 bytes to 1058866 bytes? I assume that gifsicle is trying the first level of optimizations, as per the documentation: https://www.lcdf.org/gifsicle/man.html
Is it possible to 100% disable any optimizations? Thanks! |
This isn't caused by optimizations, but by recompression. I don't think it's possible to tell gifsicle not to recompress anything. You could check if the image already fits your required size, and then not run gifsicle at all. |
Please let me know of some email or place where I can send the original GIF used for this.
Several GIFs uploaded by our members become larger than the original, even though I only use gifsicle to process them. The main reason I use gifsicle is to reduce the space of uploaded GIFs.
Example here:
$ /usr/local/bin/gifsicle -O3 -Okeep-empty --lossy=80 --careful --no-extensions --resize-fit 720x720 Original.gif -o Compressed1.gif
$ /usr/local/bin/gifsicle -O3 -Okeep-empty --lossy=80 --careful --no-extensions Original.gif -o Compressed2.gif
$ /usr/local/bin/gifsicle -O3 -Okeep-empty --lossy=80 --no-extensions Original.gif -o Compressed3.gif
$ /usr/local/bin/gifsicle -O2 -Okeep-empty --lossy=80 --no-extensions Original.gif -o Compressed4.gif
$ /usr/local/bin/gifsicle -O3 -Okeep-empty --no-extensions Original.gif -o Compressed5.gif
$ ls -l
1010151 Original.gif
1353192 Compressed1.gif
1353192 Compressed2.gif
1349871 Compressed3.gif
1382477 Compressed4.gif
1076116 Compressed5.gif
"lossy" seems to have the biggest impact in making the file size larger.
Without lossy, and only with "-O3" the file is still slightly larger than the original.
The text was updated successfully, but these errors were encountered: