Meet Dr. Eddie Kohler, a GIF creator’s best friend!
Scattered across the wacky animated set above is Eddie Kohler, professor of computer science at Harvard and the author of gifsicle since 1997. When it came time for Tumblr to reexamine how we manipulate GIFs, every engineer who looked at the problem inevitably came upon gifsicle, and every engineer eventually came to the same conclusion: the performance is stunning, but the quality just isn’t there. If you read between the lines of this post, sampling was obviously the issue.
Late last year, we got in touch with Eddie. After we came to a mutual understanding of the problem, Eddie agreed to come visit us in New York. We spent Friday the 13th basking in the warm, coal-fired glow of the GIF format and how to process it.
By the end of the day we had a handshake-deal for Tumblr to sponsor some feature development on gifsicle, and what we are releasing now is the result of that work.
I would love to say there was a mutual “eureka” moment, but that would be a lie. Eddie showed up with some brilliant ideas about how to handle resizing while maintaining performance and quality.
Eddie added several resampling methods, including some hybrid modes. None are as fast as the “naïve” default method, but the results are simply much better.
Our old tool threw away all the palette information, resizing as if there were no color limits, and then took a second pass to try to create the optimum palette for the image. This is slow and takes a ton of memory and can leave images looking muddy unless you sharpen them afterwards.
Gifsicle takes a very different approach. Scaling and resampling use 45-bit RGB colors (extra precision to allow a safe round-trip through gamma correction), but the results are fit to the original image’s color palette. This works for the vast majority of images while still avoiding the problem of having to choose which colors will be selected for the 512-color maximum palette (256 global and 256 frame-local colors). Despite my skepticism, this works amazingly well.
The last change made here was to allow optional expansion of the palette for small-palette images. When reducing the size of a 2-color black-and-white GIF, it is nice to be able to use a few shades of gray for some of the pixels.
As previously mentioned, we took a little speed hit by changing the resampling. That meant that we were only 10x faster than our previous converter instead of being 12-15x faster. The images are significantly smaller, too. Perhaps the biggest thing is that it is highly unlikely that a resize to smaller dimensions will create a bigger file. So now the animation you lovingly crafted and optimized to be under a megabyte won’t surprise you by timing out or exploding in size and getting rejected.
The bottom line: our rejection rate using our old tool is estimated to be 4.46% of all original GIFs. Using gifsicle reduces that to 0.68% of all submitted GIFs, and no rejection of GIFs under 1MB. Oh, and your submissions will complete much faster.
Eddie isn’t a Tumblr user, so send any thanks to him on Twitter.