{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/images/config.go#L307-L343","documentation":"The resize action scales the image and can derive one dimension from the aspect ratio, but it needs at least one of width or height. If both are 0 there is nothing to resize to, so Hugo rejects the call.","triggerScenarios":"{{ $img.Resize \"q80\" }} or {{ $img.Resize \"webp\" }} — an option string with quality/format/filter tokens but no size token; or a size token like \"x\" where both sides are empty.","commonSituations":"Using .Resize just to convert format or change quality (the correct pattern is images.Process or including a dimension); template variables for width/height both resolving to empty strings.","solutions":["Add at least one dimension: {{ $img.Resize \"600x\" }} or {{ $img.Resize \"x400\" }}.","If you only want format/quality conversion without resizing, use {{ $img.Process \"webp q80\" }} instead of .Resize.","Check that dynamically-built size strings aren't empty."],"exampleFix":"<!-- before -->\n{{ $img.Resize \"webp q80\" }}\n<!-- after -->\n{{ $img.Process \"webp q80\" }}","handlingStrategy":"validation","validationCode":"if action == \"resize\" && w == 0 && h == 0 {\n    return errors.New(\"resize requires width or height\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["For Resize, always supply at least one dimension (\"600x\", \"x400\", or \"600x400\")","Guard against empty or filter-only spec strings reaching Resize","Test template partials with each accepted spec form"],"tags":["hugo","image-processing","template","validation"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}