{"record":{"id":"fc75e83b868a6e5f","repo":"gohugoio/hugo","slug":"must-provide-width-and-height","errorCode":null,"errorMessage":"must provide Width and Height","messagePattern":"must provide Width and Height","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/config.go","lineNumber":321,"sourceCode":"\t\t\t\tif len(widthHeight) == 2 {\n\t\t\t\t\tsecond := widthHeight[1]\n\t\t\t\t\tif second != \"\" {\n\t\t\t\t\t\tc.Height, err = strconv.Atoi(second)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn c, err\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn c, errors.New(\"invalid image dimensions\")\n\t\t\t}\n\t\t}\n\t}\n\n\tswitch c.Action {\n\tcase ActionCrop, ActionFill, ActionFit:\n\t\tif c.Width == 0 || c.Height == 0 {\n\t\t\treturn c, errors.New(\"must provide Width and Height\")\n\t\t}\n\tcase ActionResize:\n\t\tif c.Width == 0 && c.Height == 0 {\n\t\t\treturn c, errors.New(\"must provide Width or Height\")\n\t\t}\n\tdefault:\n\t\tif c.Width != 0 || c.Height != 0 {\n\t\t\treturn c, errors.New(\"width or height are not supported for this action\")\n\t\t}\n\t}\n\n\tif err := c.init(defaults.Config, sourceFormat); err != nil {\n\t\treturn c, err\n\t}\n\n\tif mainImageVersionNumber > 0 {\n\t\toptions = append(options, strconv.Itoa(mainImageVersionNumber))\n\t}","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/images/config.go#L303-L339","documentation":"For the Crop, Fill, and Fit actions Hugo needs an exact target box, so both width and height must be supplied. The switch at config.go:319-322 returns this error when either dimension is zero for those actions.","triggerScenarios":"Calling `.Crop`, `.Fill`, or `.Fit` with only one dimension, e.g. `{{ $img.Crop \"100x\" }}` or `{{ $img.Fit \"q80\" }}` (no box at all).","commonSituations":"Assuming Crop/Fill/Fit preserve aspect ratio like Resize (they don't — they need a box); forgetting the height token; passing only a `q` token.","solutions":["Supply both width and height for Crop/Fill/Fit, e.g. `{{ $img.Fill \"300x200\" }}`.","Switch to `.Resize` if you want aspect-ratio-preserving scaling with a single dimension.","Re-check the action semantics: Resize needs one, Crop/Fill/Fit need both."],"exampleFix":"{{/* before */}}\n{{ $img.Fill \"300x\" }}\n\n{{/* after */}}\n{{ $img.Fill \"300x200\" }}","handlingStrategy":"validation","validationCode":"switch action {\ncase \"crop\", \"fill\", \"fit\":\n    if width == 0 || height == 0 { return errors.New(\"must provide Width and Height\") }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Crop/Fill/Fit always need both dimensions.","Use Resize when you want aspect-ratio-preserving single-dimension scaling."],"tags":["hugo","image-processing","templates","validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}