{"id":"79c5ee2f6c7f4f00","repo":"gohugoio/hugo","slug":"quality-ranges-from-1-to-100-inclusive","errorCode":null,"errorMessage":"quality ranges from 1 to 100 inclusive","messagePattern":"quality ranges from 1 to 100 inclusive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/config.go","lineNumber":285,"sourceCode":"\t\t\tc.Filter = filter\n\t\t} else if _, ok := hints[part]; ok {\n\t\t\tc.Hint = part\n\t\t} else if _, ok := compressionMethods[part]; ok {\n\t\t\tc.Compression = part\n\t\t} else if f, ok := ImageFormatFromExt(\".\" + part); ok {\n\t\t\tc.TargetFormat = f\n\t\t} else if part[0] == '#' {\n\t\t\tc.BgColor, err = hexStringToColorGo(part[1:])\n\t\t\tif err != nil {\n\t\t\t\treturn c, err\n\t\t\t}\n\t\t} else if part[0] == 'q' {\n\t\t\tc.Quality, err = strconv.Atoi(part[1:])\n\t\t\tif err != nil {\n\t\t\t\treturn c, err\n\t\t\t}\n\t\t\tif c.Quality < 1 || c.Quality > 100 {\n\t\t\t\treturn c, errors.New(\"quality ranges from 1 to 100 inclusive\")\n\t\t\t}\n\t\t} else if part[0] == 'r' {\n\t\t\tc.Rotate, err = strconv.Atoi(part[1:])\n\t\t\tif err != nil {\n\t\t\t\treturn c, err\n\t\t\t}\n\t\t} else if strings.Contains(part, \"x\") {\n\t\t\twidthHeight := strings.Split(part, \"x\")\n\t\t\tif len(widthHeight) <= 2 {\n\t\t\t\tfirst := widthHeight[0]\n\t\t\t\tif first != \"\" {\n\t\t\t\t\tc.Width, err = strconv.Atoi(first)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn c, err\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif len(widthHeight) == 2 {","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/images/config.go#L267-L303","documentation":"Hugo parses image-processing option strings (e.g. from .Resize/.Fill/.Fit template calls) and treats any token starting with 'q' as a quality spec. After strconv.Atoi succeeds, the value is range-checked; anything outside 1–100 is rejected because JPEG/WebP/AVIF encoders only accept that range.","triggerScenarios":"Calling {{ $img.Resize \"300x q0\" }}, \"q101\", \"q150\", or any qN option with N < 1 or N > 100 in a Resize/Fill/Fit/Crop/Filter option string or in Markdown image render hooks that forward such options.","commonSituations":"Typos like q1000 instead of q100; templates computing quality dynamically (e.g. from front matter) that produce 0; confusing 0 as 'default' when the way to get the default is to omit q entirely.","solutions":["Change the q token to a value between 1 and 100, e.g. q75.","Omit the q option entirely to fall back to imaging.quality from site config.","If the quality is computed in a template, clamp it: {{ math.Max 1 (math.Min 100 $q) }}."],"exampleFix":"<!-- before -->\n{{ $img := $img.Resize \"600x q0\" }}\n<!-- after -->\n{{ $img := $img.Resize \"600x q75\" }}","handlingStrategy":"validation","validationCode":"if q < 1 || q > 100 {\n    return fmt.Errorf(\"quality %d out of range [1,100]\", q)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp or validate quality (q1–q100 in the spec string) before building the image processing spec","In templates, only pass literal qN values in the 1–100 range","Centralize image option construction in one helper so the range check lives in one place"],"tags":["hugo","image-processing","template","validation"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}