gohugoio/hugo · error
invalid image dimensions
Error message
invalid image dimensions
What it means
`DecodeImageConfig` parses a `WxH` dimension token by splitting on `x`. If splitting yields more than two parts (i.e. the token contains more than one `x`), the dimension spec is ambiguous and rejected as invalid at config.go:313.
Solutions
- Provide at most a single `WxH` pair, e.g. `100x200`.
- Use `100x` (width only) or `x200` (height only) when you want one dimension.
- Strip any stray characters/units from the option string.
Example fix
{{/* before */}}
{{ $img.Resize "100x200x50" }}
{{/* after */}}
{{ $img.Resize "100x200" }} Defensive patterns
Strategy: validation
Validate before calling
if strings.Count(dimToken, "x") > 1 { return errors.New("invalid image dimensions") } Prevention
- A dimension token is WxH with at most one x.
- Use 100x or x100 for single-dimension resize.
When it happens
Trigger: An image option string containing multiple `x` characters in a dimension token, e.g. `{{ $img.Resize "100x200x50" }}` or a value like `2x2x`.
Common situations: Accidental extra `x`; trying to express a third dimension or DPI; malformed copy-paste of a dimension string; a filename or unit leaking into the option string.
Related errors
- must provide Width and Height
- must provide Width or Height
- quality ranges from 1 to 100 inclusive
- width or height are not supported for this action
- 'pager size' must be a positive integer
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/61a85242a1f75194.
Report an issue: GitHub.
Appendix: source
Thrown at resources/images/config.go:313
first := widthHeight[0]
if first != "" {
c.Width, err = strconv.Atoi(first)
if err != nil {
return c, err
}
}
if len(widthHeight) == 2 {
second := widthHeight[1]
if second != "" {
c.Height, err = strconv.Atoi(second)
if err != nil {
return c, err
}
}
}
} else {
return c, errors.New("invalid image dimensions")
}
}
}
switch c.Action {
case ActionCrop, ActionFill, ActionFit:
if c.Width == 0 || c.Height == 0 {
return c, errors.New("must provide Width and Height")
}
case ActionResize:
if c.Width == 0 && c.Height == 0 {
return c, errors.New("must provide Width or Height")
}
default:
if c.Width != 0 || c.Height != 0 {
return c, errors.New("width or height are not supported for this action")
}
}View on GitHub (pinned to 52c9bd7908)