Skip to content

Why GIF Quality has no effect

Copy page

Changing GifExportParams.Quality in govips can leave a GIF entirely unchanged. These static GIFs, generated from the same project-owned photograph, separate that legacy field from the controls that actually affect palette encoding.

Every variant starts from the same pixels at 600×400. Compare govips with Quality=10 and Quality=90, then explore the effective parameters and other entries. Parameters, byte sizes, and decoded colour counts come from the actual files. Each image is downloadable.

govips v2.20.0 / libvips 8.17.3

Reference input · govips · Reference
Reference input600 × 400, 472,176 bytes{"height":400,"width":600}ICC: 3048 bytesDownload generated output
Baseline: 8 bit / Dither 1 / Effort 7 · govips · Reference
Baseline: 8 bit / Dither 1 / Effort 7600 × 400, 142,997 bytes{"Bitdepth":8,"Dither":1,"Effort":7,"Quality":90}Decoded RGB colours: 255Download generated output
Only Quality=10 · govips · Reference
Only Quality=10600 × 400, 142,997 bytes{"Bitdepth":8,"Dither":1,"Effort":7,"Quality":10}Decoded RGB colours: 255Download generated output
Only Quality=90 · govips · Reference
Only Quality=90600 × 400, 142,997 bytes{"Bitdepth":8,"Dither":1,"Effort":7,"Quality":90}Decoded RGB colours: 255Download generated output
Only Bitdepth=4 · govips · Reference
Only Bitdepth=4600 × 400, 55,370 bytes{"Bitdepth":4,"Dither":1,"Effort":7,"Quality":90}Decoded RGB colours: 16Download generated output
Only Dither=0 · govips · Reference
Only Dither=0600 × 400, 142,997 bytes{"Bitdepth":8,"Dither":0,"Effort":7,"Quality":90}Decoded RGB colours: 255Download generated output
govips: Dither=0.01 · govips · Reference
govips: Dither=0.01600 × 400, 134,365 bytes{"Bitdepth":8,"Dither":0.01,"Effort":7,"Quality":90}Decoded RGB colours: 255Download generated output
Only Effort=1 · govips · Reference
Only Effort=1600 × 400, 150,842 bytes{"Bitdepth":8,"Dither":1,"Effort":1,"Quality":90}Decoded RGB colours: 255Download generated output
Only Effort=10 · govips · Reference
Only Effort=10600 × 400, 142,192 bytes{"Bitdepth":8,"Dither":1,"Effort":10,"Quality":90}Decoded RGB colours: 255Download generated output

Native libvips gifsave has no JPEG-style quality option. The govips field exists for the ImageMagick fallback used with older libvips versions. With govips v2.20.0 / libvips 8.17.3 and its native saver, the two Quality values produce identical GIF bytes and identical decoded pixels in this example.

That establishes the behaviour of this native path, rather than every version or similarly named parameter. Sharp’s GIF options do not expose this legacy govips field; the other three entries do not invent a Quality comparison.

Goal Change in this example Interpretation
Limit palette size Change only Bitdepth from 8 to 4; sharp uses colours: 16 This sets an upper bound. Input colours and reserved transparency indices affect the actual count; do not expect exactly 16 or 256 colours
Inspect dithering Keep 8 bit / Effort 7 and change only Dither from 1 to 0 Look at sky gradients, dark areas, and grain. Dithering does not add palette entries or represent a universal quality setting
Adjust encoding effort Keep 8 bit / Dither 1 and change only Effort to 1 or 10 Higher values allow more quantisation work, without guaranteeing smaller files. This example makes no timing benchmark claim

Govips v2.20.0 also has a zero-value boundary: Dither=0 is not forwarded to the native saver, so the underlying default still applies. Its pixels therefore match the baseline. The additional Dither=0.01 variant takes effect, but represents low dithering rather than disabling it. A value of 0 is verified to disable dithering in sharp, pyvips, and the CLI. Cards show requested parameters so forwarding differences remain visible. interlace controls progressive loading; this example neither treats it as a quality control nor presents an unverified govips switch.

All four entries have executed. Govips supplies the reference outputs; use the tabs above to inspect the other entries and their parameters. General pixel equivalence between entries remains unverified.

Run command

go run . photo.jpg output/

Complete source

package main

import (
	"fmt"
	"os"
	"path/filepath"

	"github.com/davidbyttow/govips/v2/vips"
	"github.com/webp-sh/vips-handbook/examples/internal/recipeutil"
)

func main() {
	if err := run(os.Args); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
func run(args []string) error {
	if len(args) != 3 {
		return fmt.Errorf("usage: main INPUT OUTPUT_DIRECTORY")
	}
	if err := os.MkdirAll(args[2], 0o755); err != nil {
		return err
	}
	if err := vips.Startup(nil); err != nil {
		return err
	}
	defer vips.Shutdown()
	outputs := []recipeutil.Output{}
	variants := []struct {
		id                        string
		quality, bitdepth, effort int
		dither                    float64
	}{
		{"baseline", 90, 8, 7, 1}, {"quality-10", 10, 8, 7, 1}, {"quality-90", 90, 8, 7, 1},
		{"bitdepth-4", 90, 4, 7, 1}, {"dither-0", 90, 8, 7, 0}, {"dither-near-zero", 90, 8, 7, 0.01}, {"effort-1", 90, 8, 1, 1}, {"effort-10", 90, 8, 10, 1},
	}
	for _, variant := range variants {
		output, err := makeVariant(args[1], args[2], variant.id, variant.quality, variant.bitdepth, variant.effort, variant.dither)
		if err != nil {
			return err
		}
		outputs = append(outputs, output)
	}
	image, err := vips.NewImageFromFile(args[1])
	if err != nil {
		return err
	}
	defer image.Close()
	if err := image.Resize(600.0/float64(image.Width()), vips.KernelLanczos3); err != nil {
		return err
	}
	output, err := recipeutil.ExportPng(image, args[2], "source.png", map[string]any{"width": 600, "height": 400})
	if err != nil {
		return err
	}
	outputs = append(outputs, output)
	return recipeutil.WriteResult(args[2], "gif-quality", args[1], outputs)
}

func makeVariant(input, dir, id string, quality, bitdepth, effort int, dither float64) (recipeutil.Output, error) {
	image, err := vips.NewImageFromFile(input)
	if err != nil {
		return recipeutil.Output{}, err
	}
	defer image.Close()
	if err := image.Resize(600.0/float64(image.Width()), vips.KernelLanczos3); err != nil {
		return recipeutil.Output{}, err
	}
	params := vips.NewGifExportParams()
	params.Quality = quality
	params.Bitdepth = bitdepth
	params.Effort = effort
	params.Dither = dither
	data, meta, err := image.ExportGIF(params)
	if err != nil {
		return recipeutil.Output{}, err
	}
	name := id + ".gif"
	if err := os.WriteFile(filepath.Join(dir, name), data, 0o644); err != nil {
		return recipeutil.Output{}, err
	}
	return recipeutil.Output{Path: name, Format: "gif", Width: meta.Width, Height: meta.Height, Size: len(data), Parameters: map[string]any{"Quality": quality, "Bitdepth": bitdepth, "Dither": dither, "Effort": effort}}, nil
}
  1. Decode every GIF and confirm 600×400 dimensions, so a size change caused by resizing cannot masquerade as an encoding effect.
  2. Compare bytes and decoded pixels for the two Quality values. Both comparisons pass as identical here.
  3. Count decoded RGB colours in the low-bit-depth output and check the upper bound; compare effective Dither values for changed pixels. For govips, also check that 0 is ignored and 0.01 takes effect.
  4. Choose parameters using both the image and byte size, without predicting a fixed reduction from the Effort value.

Reviewed on 2026-10-26. Reference: govips v2.20.0 / libvips 8.17.3. Sharp 0.35.5 uses bundled libvips 8.18.7; pyvips 3.2.0 and the CLI use libvips 8.17.3.

This is a photograph-to-static-GIF example. It does not verify the older ImageMagick fallback or animation optimisation. For missing frames and page-height problems, see animation and multipage images.