gohugoio/hugo · error

imaging.webp.compression must be one of lossy or lossless…

Error message

imaging.webp.compression must be one of lossy or lossless, got %q

What it means

Validates the WebP compression method after lowercasing and fallback. Must be 'lossy' or 'lossless' (defined in compressionMethods). If unset, inherits the global compression, then defaults to 'lossy'. Only checked when non-empty after resolution.

Solutions

  1. Set imaging.webp.compression to 'lossy' or 'lossless'.
  2. Omit the key to use the default 'lossy'.
  3. WebP lossless is good for logos, icons, and screenshots with sharp edges and few colors.

Example fix

# before (hugo.toml)
[imaging.webp]
compression = "high"

# after
[imaging.webp]
compression = "lossy"
Defensive patterns

Strategy: validation

Validate before calling

// Validate WebP compression
func validateWebpCompression(c string) error {
    c = strings.ToLower(c)
    if c != "" && c != "lossy" && c != "lossless" {
        return fmt.Errorf("invalid webp compression %q; valid: lossy, lossless", c)
    }
    return nil
}

Prevention

When it happens

Trigger: Setting imaging.webp.compression (or the global imaging.compression) to any string other than lossy or lossless. Case-insensitive.

Common situations: Typo 'losless'; 'high'; using a value from a different encoder.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/a6e0cfa65261bc46. Report an issue: GitHub.

Appendix: source

Thrown at resources/images/config.go:788

	}
	if c.Compression == "" {
		c.Compression = defaultCompression
	}
	if c.Quality == 0 {
		c.Quality = 75
	}

	c.Hint = strings.ToLower(c.Hint)
	c.Compression = strings.ToLower(c.Compression)

	if c.Hint != "" && !hints[c.Hint] {
		return fmt.Errorf("imaging.webp.hint must be one of picture, photo, drawing, icon, or text, got %q", c.Hint)
	}
	if c.Method < 0 || c.Method > 6 {
		return fmt.Errorf("imaging.webp.method must be between 0 and 6, got %d", c.Method)
	}
	if c.Compression != "" && !compressionMethods[c.Compression] {
		return fmt.Errorf("imaging.webp.compression must be one of lossy or lossless, got %q", c.Compression)
	}
	if c.Quality < 1 || c.Quality > 100 {
		return fmt.Errorf("imaging.webp.quality must be between 1 and 100 inclusive, got %d", c.Quality)
	}
	return nil
}

View on GitHub (pinned to 52c9bd7908)