gohugoio/hugo · error
must provide Width or Height
Error message
must provide Width or Height
What it means
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.
Source
Thrown at resources/images/config.go:325
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")
}
}
if err := c.init(defaults.Config, sourceFormat); err != nil {
return c, err
}
if mainImageVersionNumber > 0 {
options = append(options, strconv.Itoa(mainImageVersionNumber))
}
if v := formatVersionNumbers[c.TargetFormat]; v > 0 {
options = append(options, "tfv"+strconv.Itoa(v))
}View on GitHub ↗ (pinned to 8a468df065)
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.
Example fix
<!-- before -->
{{ $img.Resize "webp q80" }}
<!-- after -->
{{ $img.Process "webp q80" }} Defensive patterns
Strategy: validation
Validate before calling
if action == "resize" && w == 0 && h == 0 {
return errors.New("resize requires width or height")
} Prevention
- 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
When it happens
Trigger: {{ $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.
Common situations: 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.
Related errors
- quality ranges from 1 to 100 inclusive
- invalid image dimensions
- must provide Width and Height
- width or height are not supported for this action
- imaging.quality must be between 1 and 100 inclusive, got %d
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/726d2d36c8f515e7.json.
Report an issue: GitHub ↗.