gohugoio/hugo · error
must provide Width and Height
Error message
must provide Width and Height
What it means
The crop, fill, and fit image actions must know the exact target box, so Hugo requires both width and height to be non-zero after parsing the option string. A missing dimension leaves it at 0, which these actions cannot work with.
Source
Thrown at resources/images/config.go:321
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")
}
}
if err := c.init(defaults.Config, sourceFormat); err != nil {
return c, err
}
if mainImageVersionNumber > 0 {
options = append(options, strconv.Itoa(mainImageVersionNumber))
}View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Provide both dimensions: {{ $img.Fill "600x400" }}.
- If you only want to constrain one dimension with aspect preserved, use .Resize instead of Fill/Fit/Crop.
- When dimensions come from variables, validate both are > 0 before calling the method.
Example fix
<!-- before -->
{{ $img.Fill "600x" }}
<!-- after -->
{{ $img.Fill "600x400" }} Defensive patterns
Strategy: validation
Validate before calling
if action == "crop" || action == "fill" || action == "fit" {
if w == 0 || h == 0 {
return errors.New("crop/fill/fit require both width and height")
}
} Prevention
- Know the per-action contract: Crop, Fill, and Fit require both dimensions (e.g. "600x400")
- Validate the spec string with both components present before calling the API
- Encode action→required-dimensions rules in a table shared by all callers
When it happens
Trigger: {{ $img.Fill "600x" }}, {{ $img.Crop "x400" }}, {{ $img.Fit "600" }} (no 'x' at all leaves both 0), or an images.Process call with action crop/fill/fit and an incomplete size spec.
Common situations: Habitually using the one-dimension form that works for Resize with Fill/Fit/Crop; templates where one dimension variable is empty/zero; migrating from .Resize to .Fill without adding the second dimension.
Related errors
- quality ranges from 1 to 100 inclusive
- invalid image dimensions
- must provide Width or 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/fc75e83b868a6e5f.json.
Report an issue: GitHub ↗.