{"id":"b534f25d3f5e4046","repo":"gohugoio/hugo","slug":"imaging-avif-compression-must-be-one-of-lossy-or-l","errorCode":null,"errorMessage":"imaging.avif.compression must be one of lossy or lossless, got %q","messagePattern":"imaging\\.avif\\.compression must be one of lossy or lossless, got %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/config.go","lineNumber":725,"sourceCode":"\tif c.Compression == \"\" {\n\t\tc.Compression = defaultCompression\n\t}\n\tif c.Quality == 0 {\n\t\tc.Quality = 60\n\t}\n\n\tc.Hint = strings.ToLower(c.Hint)\n\tc.Compression = strings.ToLower(c.Compression)\n\n\tif c.Hint != \"\" && !hints[c.Hint] {\n\t\treturn fmt.Errorf(\"imaging.avif.hint must be one of picture, photo, drawing, icon, or text, got %q\", c.Hint)\n\t}\n\tif c.EncoderSpeed < 1 || c.EncoderSpeed > 10 {\n\t\treturn fmt.Errorf(\"imaging.avif.encoderSpeed must be between 1 and 10, got %d\", c.EncoderSpeed)\n\t}\n\n\tif c.Compression != \"\" && !compressionMethods[c.Compression] {\n\t\treturn fmt.Errorf(\"imaging.avif.compression must be one of lossy or lossless, got %q\", c.Compression)\n\t}\n\tif c.Quality < 1 || c.Quality > 100 {\n\t\treturn fmt.Errorf(\"imaging.avif.quality must be between 1 and 100 inclusive, got %d\", c.Quality)\n\t}\n\n\treturn nil\n}\n\n// WebpConfig holds WebP-specific encoding configuration.\ntype WebpConfig struct {\n\t// Quality setting (1-100). Falls back to the global imaging.quality if unset.\n\t// Only relevant for lossy encoding.\n\tQuality int\n\n\t// Compression method to use.\n\t// One of \"lossy\" or \"lossless\".\n\tCompression string\n","sourceCodeStart":707,"sourceCodeEnd":743,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/images/config.go#L707-L743","documentation":"Hugo validates AVIF encoder settings in AvifConfig.init when loading site configuration. The `imaging.avif.compression` value (after lowercasing and falling back to the global `imaging.compression` or the default) must be a key in the compressionMethods set — only \"lossy\" or \"lossless\" are supported by the AVIF encoder.","triggerScenarios":"Setting `[imaging.avif] compression = \"something-else\"` (or a global `[imaging] compression`) in hugo.toml/config to any string other than lossy/lossless. Fires at config load / site build time, before any image is processed. Note the value inherits from the global `imaging.compression`, so a bad global value also trips this AVIF-specific check.","commonSituations":"Copying JPEG/PNG-style options like \"none\", \"best\", \"medium\", or numeric compression levels from other tools; typos like \"loseless\"; setting the global imaging.compression for WebP and not realizing it also applies to AVIF.","solutions":["Set `imaging.avif.compression` (or the inherited global `imaging.compression`) to exactly \"lossy\" or \"lossless\" in your site config.","Remove the key entirely to use the default compression.","If you meant to control quality, use `imaging.avif.quality` (1-100) instead."],"exampleFix":"# before (hugo.toml)\n[imaging.avif]\ncompression = \"high\"\n# after\n[imaging.avif]\ncompression = \"lossy\"\nquality = 60","handlingStrategy":"validation","validationCode":"valid := map[string]bool{\"lossy\": true, \"lossless\": true}\nif !valid[strings.ToLower(cfg.Imaging.AVIF.Compression)] {\n    return fmt.Errorf(\"avif compression must be lossy or lossless\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set imaging.avif.compression in hugo.toml only to \"lossy\" or \"lossless\"","Validate site config with `hugo config` before builds","Keep an enum of allowed values in deployment scripts that generate config"],"tags":["hugo","config","imaging","avif"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}