{"record":{"id":"726d2d36c8f515e7","repo":"gohugoio/hugo","slug":"must-provide-width-or-height","errorCode":null,"errorMessage":"must provide Width or Height","messagePattern":"must provide Width or Height","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/config.go","lineNumber":325,"sourceCode":"\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}\n\n\tif v := formatVersionNumbers[c.TargetFormat]; v > 0 {\n\t\toptions = append(options, \"tfv\"+strconv.Itoa(v))\n\t}","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/images/config.go#L307-L343","documentation":"The Resize action scales an image and needs at least one of width or height to know the target size (the other is derived to preserve aspect ratio). config.go:323-326 rejects Resize when both dimensions are zero.","triggerScenarios":"Calling `.Resize` with no dimension token, e.g. `{{ $img.Resize \"q80 jpg\" }}` (quality/format only, no size).","commonSituations":"Wanting a pure format conversion with `Resize` (use a format token without an action, or an explicit action that supports no dimensions); forgetting to add the size; assuming quality alone triggers a resize.","solutions":["Add at least one dimension, e.g. `{{ $img.Resize \"300x\" }}`.","For format-only conversion, drop the `resize` action and just specify the format token, e.g. `{{ $img.Resize \"jpg\" }}` still needs a size — instead use a non-resize action or the imaging config."],"exampleFix":"{{/* before */}}\n{{ $img.Resize \"q80 jpg\" }}\n\n{{/* after */}}\n{{ $img.Resize \"300x q80 jpg\" }}","handlingStrategy":"validation","validationCode":"if action == \"resize\" && width == 0 && height == 0 { return errors.New(\"must provide Width or Height\") }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resize needs at least one dimension.","For format-only conversion, avoid the resize action."],"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"}