gohugoio/hugo · error

must provide Width or Height

Error message

must provide Width or Height

What it means

The Resize action scales an image and needs at least one of width or height to know the target size (the other is derived to preserve aspect ratio). config.go:323-326 rejects Resize when both dimensions are zero.

Solutions

  1. Add at least one dimension, e.g. `{{ $img.Resize "300x" }}`.
  2. For format-only conversion, drop the `resize` action and just specify the format token, e.g. `{{ $img.Resize "jpg" }}` still needs a size — instead use a non-resize action or the imaging config.

Example fix

{{/* before */}}
{{ $img.Resize "q80 jpg" }}

{{/* after */}}
{{ $img.Resize "300x q80 jpg" }}
Defensive patterns

Strategy: validation

Validate before calling

if action == "resize" && width == 0 && height == 0 { return errors.New("must provide Width or Height") }

Prevention

When it happens

Trigger: Calling `.Resize` with no dimension token, e.g. `{{ $img.Resize "q80 jpg" }}` (quality/format only, no size).

Common situations: Wanting a pure format conversion with `Resize` (use a format token without an action, or an explicit action that supports no dimensions); forgetting to add the size; assuming quality alone triggers a resize.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/726d2d36c8f515e7. Report an issue: GitHub.

Appendix: 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 52c9bd7908)