

Now that we have the hard-coded version, we’ll break this up into placeholders ( using proper escaping for shell arguments, of course) and we’ll find ourselves with the full, variable-filled version we had before! Gotchas With these numbers at hand, we can ask Gifsicle to resize our image to 267×150: Given the height, we can calculate the width thusly: $src_width / $src_height * $dst_height, or 500 / 281 * 150, which gives us a width of 267px. Confused? Just remember that we have a 16:9 aspect ratio, meaning the height is the smaller dimension and thus cannot end up smaller than 150px or we risk our 150×150 frame not being filled. Now, let’s say we want a square version of that same image, at 150×150. In order to achieve this, we need to perform two operations: resizing the image to fit as much of it as possible into a 150×150 box, then crop off anything outside that area.įortunately, resizing the image is easy: Gifsicle has a -resize option, and the math that led us to our getimagesize()-compatible calculations up above would tell us that to fit a 500×281 image in a 150×150 box, our target dimensions would be 267×150. The original dimensions of this image are 500×281, approximately a 16:9 aspect ratio. Virtualdub's built-in gif encoder was un-watchable.Ġ1 error_dither.bat - Gunner Girls 002_optimized.Well, that was easy, wasn’t it? In case you’re not well-versed in juggling arguments and using PHP to assemble CLI commands, we’ll apply some real numbers: let’s say we have this gif of America’s Sweetheart, Nick Offerman: The only way that I could get anything almost as good as (nothing was as good as) the drag and drop, optimized encode which was 22.6MB was by using Photoshop which produced a 17.1MB file. All of the other encodes show some king of artifacts. All of these encodes were using the external encoder in Virtualdub, using every single dithering method except for the error_dither.bat drag and drop encode which looks great. Well, ed_dither was a little bigger in file size (12,422KB). I've tried ffmpeg as the encoder and gifsicle as the muxer but everything that I've tried has left me with a file that is the same size (9,747KB) and looks the same as the others. I've tried using just ffmpeg with different dithering methods and I tried using just gifsicle. The second one (the first one did not work).

I've played with this for days and the best I can do is with MaverickTse's FFgif program.

Photoshop 128color, adaptive 50% diffusion, lossy5 214KB Gimp 128color, floyd-steinberg 990KB, gifsicle optimized =>961KB Some programs like ffmpeg barely have any options, so they suffer immensely. But because of those same factors it will also benefit from using a limited palette, adaptive dithering. It's primarily greyscale on a static gradient background, so predisposed to banding as you can see with vdub's default export. Here are some tests with an animation I did a few years ago (don't take the content too seriously, it was just for fun ). It can reduce the filesize of most gifs, but for already optimized ones like those produced in photoshop, the filesize actually gets larger
GIFSICLE IN GIMP FREE
What works well for some types of content might not be appropriate for others - so it's important to have options.Ī free gif optimization program is gifsicle (commandline only). What makes or breaks a gif in terms of quality/filesize ratio is the processing options, pallete, dithering algorithms, optimizations used. Haha racer-x GIF boob animations used to be so popular! But now with youtube, video embedding, broadband.
