gohugoio/hugo · error

width or height are not supported for this action

Error message

width or height are not supported for this action

What it means

The switch at config.go:318-331 only allows width/height for Resize, Crop, Fill, and Fit. For any other (or no) action, specifying a dimension is meaningless and is rejected at config.go:328-330 so that silently ignored options don't mislead users.

Solutions

  1. Add a recognized action keyword (resize/crop/fill/fit) before the dimensions.
  2. Remove the dimension token if you only want format/quality conversion.
  3. Check the spelling/case of the action token — options are lower-cased, so use lowercase action names.

Example fix

{{/* before: action keyword missing/misspelled */}}
{{ $img.Process "200x100" }}

{{/* after */}}
{{ $img.Process "resize 200x100" }}
Defensive patterns

Strategy: validation

Validate before calling

if !slices.Contains([]string{"resize","crop","fill","fit"}, action) && (width != 0 || height != 0) {
    return errors.New("width or height are not supported for this action")
}

Prevention

When it happens

Trigger: Passing a `WxH` token without setting an action (no `resize`/`crop`/`fill`/`fit`), or alongside an unsupported action token, e.g. `{{ $img.Resize "200x100 jpg" }}` is fine but a bare `{{ $img.Process "200x100" }}` style call resolving to no recognized action triggers it.

Common situations: Typo in the action keyword so it isn't matched in `Actions`; expecting dimensions to imply a default resize; copy-pasting a dimension string intended for a resize into a format-conversion-only call.

Related errors


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

Appendix: source

Thrown at resources/images/config.go:329

				}
			} 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))
	}

	usesSmartCrop := c.Anchor == SmartCropAnchor && (c.Action == ActionCrop || c.Action == ActionFill)
	if smartCropVersionNumber > 0 && usesSmartCrop {
		options = append(options, strconv.Itoa(smartCropVersionNumber))

View on GitHub (pinned to 52c9bd7908)