Colours, dithering, frames, lossy reuse, crop and resize · before and after

GIF Compressor

Cut an animated GIF down by lowering the palette, dropping or merging frames, letting near-identical pixels share a colour so the compressor finds longer runs, trimming the edges or shrinking the picture. Press Compress to see the real size and both animations side by side.

1. GIF

Animated or still GIF

Drop a GIF here or click to choose

Up to 25 MB, 500 frames and 60 million pixels in all. Everything is processed in this tab.

2. Settings

A preset sets every option below, so it replaces your changes but keeps the crop.

One palette shared by all frames. With frame differences on, one of the entries stands for unchanged pixels.

A pixel keeps the colour it had in the last frame, or its left or upper neighbour's, if that is close enough. Longer runs of one index compress better; high values smear fine detail.

The dropped frames' delays are added to the kept one, so the animation lasts as long as before.

Before and after

Press Compress to see the result

Your GIF appears here.

Animated GIF Compressor

Operator: Abdulla Al Fahad. How tools are built and checked

A GIF has nothing like a quality slider, so shrinking one means working five separate levers: how many colours, how they are dithered, how many frames, how many pixels, and how far a pixel may stray from its neighbour's colour. You set each one, press Compress, and the real size and both animations appear side by side before anything is downloaded.

The lever that matters most depends on the clip. Frame differences store only the rectangle that changed, so they pay off wherever most pixels stay still between frames, as in a screen recording or a logo, and do little for footage where the whole picture moves. In the one measured illustration near the end, reducing the palette saved far less than frame differences did.

The sizes you see are what the encoder wrote, not an estimate, and a GIF that was already tightly encoded may not shrink at all, in which case you are told it did not shrink rather than being offered a larger file as an improvement.

Key features

  • A shared palette of 256, 128, 64, 32, 16, 8, 4 or 2 colours from median cut over every frame
  • Ordered (Bayer 8 x 8) or Floyd-Steinberg dithering with a strength slider, or none
  • Lossy colour reuse: a pixel keeps the colour it had in the last frame, or its left or upper neighbour's, when it is close enough
  • Keep every 2nd, 3rd, 4th or 6th frame with delays added up, and a merge for frames that look the same
  • Frame differences: later frames store only the rectangle that changed, with unchanged pixels transparent
  • Resize from 10 to 100 percent and trim any edge, then four presets that set every option
  • Real before and after sizes, dimensions, frame counts and two live previews

Palette, dithering, lossy reuse and frame handling

The page opens GIF87a and GIF89a files up to 25 MB, with at most 500 frames and 60 million pixels in total. The file is checked by its first bytes, and a truncated file is read as far as it goes, with a warning. Every frame is composited onto the full canvas first, honouring the original disposal methods and transparency, and the loop count carries over: forever stays forever, play once stays once, and a count of n stays n.

A GIF stores a table of up to 256 colours and the picture as indices into it. Here one table is shared by all frames, which keeps the file small but means a frame whose colours differ greatly from the rest is quantised with the shared table. The choices are powers of two because the table is stored that way: 100 colours would cost the same as 128. Transparency in a GIF is on or off, so any pixel with less than half opacity becomes the transparent entry, and with frame differences on one entry of the table is also given to unchanged pixels, which is why 256 colours is stored as 255 real ones.

Delays are stored in hundredths of a second. Keeping every 3rd frame of a 30-frame animation at 5 cs per frame gives 10 frames of 15 cs, 1.5 seconds in both cases. Most browsers play a delay of 0 or 1 cs as 10 cs, so very fast animations should keep their frames rather than dropping the ones in between.

Floyd-Steinberg shifts colours differently in each frame, which turns static areas into flicker and defeats frame differences. In the illustration below, the same animation that is 18,331 bytes with ordered dithering is 51,133 bytes with Floyd-Steinberg at 80 percent.

How it works

Frames are first cropped and resized with the browser's canvas, then thinned, then merged. The merge compares each frame with the last one kept, using the mean absolute difference over red, green and blue, and folds the delay into that frame when the difference is within your limit; comparing against the kept frame stops slow drift adding up to a visible jump. Next a histogram of all the remaining pixels at 5 bits per channel is cut into the chosen number of boxes by median cut, and each box becomes one palette colour.

Each pixel is then mapped to an index. With lossy reuse on, the colour the pixel would get is first compared with what the viewer already sees at that spot, the same pixel in the previous frame, and then with the pixel to its left and above, and if one is within the tolerance (0.6 colour units per slider step) that index is reused. This is done against the output, not the original, so errors cannot build up from frame to frame. Runs of equal indices are what LZW compresses best, and unchanged pixels become one transparent index inside a bounding rectangle. The writer is a standard GIF89a LZW coder with 255-byte sub-blocks.

Common use cases

  • A 4.8 MB reaction GIF for a chat app with a 2 MB limit: choose the Small preset, then raise Lossy colour reuse to 50 and lower the size to 60 percent until the result is under 2 MB. The preview shows when faces start to smear.
  • A product demo recorded from a screen, 800 x 600 px with a mouse pointer moving over a still page: frame differences store only the small rectangle round the pointer, so this kind of GIF often shrinks more than a filmed one.
  • An animated logo with 8 flat colours: choose 8 colours and no dithering. A flat picture gains nothing from dithering and loses a few kilobytes by having it.

How to use this tool

  1. Drop a GIF; its size, frame count, duration and loop count appear under the box.
  2. Pick a preset, then change what you need: colours, dithering, frames, size or trims.
  3. Press Compress and wait for the progress bar; Cancel stops it between frames.
  4. Compare the two animations and the sizes, press Compress again after any change, and download the result when it is small enough.

Example

A 30-frame GIF at 5 cs per frame (1.5 s), with the Frames menu set to Keep every 3rd frame

30 frames x 5 cs = 150 cs (1.5 s)
Keep every 2nd frame, then Keep every 3rd frame, then Keep every 4th frame

Frames and delays in the result

Keep every 2nd frame: 15 frames of 10 cs each, 1.5 s
Keep every 3rd frame: 10 frames of 15 cs each, 1.5 s
Keep every 4th frame: 8 frames, seven of 20 cs and one of 10 cs, still 1.5 s

Common pitfalls

A GIF that was already compressed by a good encoder may not shrink; when the result is the same size or larger the result says nothing was saved.

The page also writes one palette for the whole animation, so a clip that cuts between very different scenes, such as a blue sea and then a red sunset, is squeezed into a single shared set of colours and will look worse than one with a steady palette.

GIF transparency is on or off, with no partial opacity, so soft edges such as a drop shadow or an anti-aliased cut-out become hard-edged and can show a halo on a coloured page. A GIF with transparent pixels is also stored as whole frames, so frame differences are skipped and it shrinks less than an opaque one.

  • Try 64 colours with ordered dithering before reaching for frame dropping. Palette size costs far less motion smoothness than losing frames does.
  • Trim before you shrink. Cropping out a margin of 40 px on each side of a 400 px wide GIF removes 20 percent of the pixels and no detail from the part you keep.

Common errors and how to fix them

This is not a GIF file
The first bytes were not GIF. A file renamed to .gif from a WEBP or APNG is rejected for that reason. Convert it to a GIF first.
This GIF is too large to edit
The frames together would need more than 60 million pixels. A 1000 x 1000 px GIF is limited to 60 frames; split it, or shrink it elsewhere first.

Best practices

  • Judge the result at the size it will be shown. Lossy artefacts that look rough at full size are often invisible in a chat bubble at half that width, so set the size first and the lossy slider after.
  • Aim for a size target before touching quality: once the file is under the limit of the place you are posting it, stop lowering colours, since every step costs fidelity.

Which setting saves the most: one measured illustration

This is an illustration, not a typical clip. The test animation was generated for the purpose: 30 frames of 160 x 120 px, a gradient with a disc moving 4 px a frame, written first with every frame whole at 256 colours (175,994 bytes) and then re-encoded here. Re-encoding at 256 colours with frame differences off saved almost nothing (174,949 bytes). Switching frame differences on took it to 15,754 bytes, 91.0 percent smaller, at the full 256 colours.

The Balanced defaults (128 colours, ordered dithering at 60, lossy 20, frame differences) gave 18,331 bytes, with a mean colour error of 5.1 on a scale of 255. Going further, 64 colours with ordered dithering and lossy 40 gave 11,699 bytes and 32 colours with no dithering and lossy 60 gave 8,265, so the palette levers moved the figure by up to about 10 KB, against about 160 KB for frame differences. Floyd-Steinberg at 80 percent went the other way, to 51,133 bytes. A clip where more of the picture changes each frame gives frame differences less to remove.

What the four presets set

A preset replaces every option below it, so choose it first and adjust afterwards. Your trims are kept.

  • Gentle: 256 colours, ordered dithering at 40, no lossy reuse, every frame, identical frames merged, 100 percent size.
  • Balanced: 128 colours, ordered at 60, lossy 20, every frame, identical frames merged, 100 percent.
  • Small: 64 colours, ordered at 60, lossy 40, every 2nd frame, merge up to 2, 75 percent.
  • Smallest: 32 colours, ordered at 40, lossy 60, every 3rd frame, merge up to 3, 50 percent.

Frequently asked questions

Does lowering the colours or the size change how long the animation plays?

No. Delays are carried over frame by frame, and only dropping or merging frames changes them, by adding the removed frames' time to the one kept, so the total stays the same. The loop count is carried over as well.

Why does Floyd-Steinberg make my GIF bigger than no dithering?

It scatters error into neighbouring pixels, so the indices stop forming long runs and each frame's noise differs from the last. Both effects work against LZW and frame differences. Ordered dithering uses a fixed pattern, which repeats from frame to frame.