{"id":"61a85242a1f75194","repo":"gohugoio/hugo","slug":"invalid-image-dimensions","errorCode":null,"errorMessage":"invalid image dimensions","messagePattern":"invalid image dimensions","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/config.go","lineNumber":313,"sourceCode":"\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 {\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}","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/images/config.go#L295-L331","documentation":"When a token in the option string contains 'x', Hugo splits it into width and height. More than one 'x' (three or more segments) makes the dimension spec unparseable, so Hugo fails rather than guessing.","triggerScenarios":"A dimensions token like \"100x200x300\" in .Resize/.Fill/.Fit options — strings.Split on \"x\" yields more than two parts.","commonSituations":"Concatenation bugs when building the option string in templates (e.g. joining two size specs without a space); copy-paste errors; accidentally including an 'x'-containing word that isn't a recognized action/anchor/filter so it's parsed as dimensions.","solutions":["Fix the dimension token to WIDTHxHEIGHT, WIDTHx, or xHEIGHT (e.g. \"600x400\", \"600x\").","If building the string dynamically, ensure options are space-separated: printf \"%dx%d webp\" $w $h.","Check for stray tokens containing 'x' that were meant to be something else."],"exampleFix":"<!-- before -->\n{{ $img.Fill \"600x400x2\" }}\n<!-- after -->\n{{ $img.Fill \"600x400\" }}","handlingStrategy":"validation","validationCode":"if w < 0 || h < 0 {\n    return errors.New(\"width and height must be non-negative\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate parsed dimensions are non-negative integers before invoking Resize/Fit/Fill","Reject dimension strings that fail strconv.Atoi instead of passing them through","Add unit tests for boundary values (0, negative, huge) on any code that builds dimension specs"],"tags":["hugo","image-processing","template","validation"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}