{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/images/config.go#L303-L339","documentation":"The crop, fill, and fit image actions must know the exact target box, so Hugo requires both width and height to be non-zero after parsing the option string. A missing dimension leaves it at 0, which these actions cannot work with.","triggerScenarios":"{{ $img.Fill \"600x\" }}, {{ $img.Crop \"x400\" }}, {{ $img.Fit \"600\" }} (no 'x' at all leaves both 0), or an images.Process call with action crop/fill/fit and an incomplete size spec.","commonSituations":"Habitually using the one-dimension form that works for Resize with Fill/Fit/Crop; templates where one dimension variable is empty/zero; migrating from .Resize to .Fill without adding the second dimension.","solutions":["Provide both dimensions: {{ $img.Fill \"600x400\" }}.","If you only want to constrain one dimension with aspect preserved, use .Resize instead of Fill/Fit/Crop.","When dimensions come from variables, validate both are > 0 before calling the method."],"exampleFix":"<!-- before -->\n{{ $img.Fill \"600x\" }}\n<!-- after -->\n{{ $img.Fill \"600x400\" }}","handlingStrategy":"validation","validationCode":"if action == \"crop\" || action == \"fill\" || action == \"fit\" {\n    if w == 0 || h == 0 {\n        return errors.New(\"crop/fill/fit require both width and height\")\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Know the per-action contract: Crop, Fill, and Fit require both dimensions (e.g. \"600x400\")","Validate the spec string with both components present before calling the API","Encode action→required-dimensions rules in a table shared by all callers"],"tags":["hugo","image-processing","template","validation"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}