lovell/sharp · error · Error

Expected create.height ${inputOptions.create.height} to be a

Error message

Expected create.height ${inputOptions.create.height} to be a multiple of create.pageHeight ${inputOptions.create.pageHeight}

What it means

Mirror of the raw.pageHeight rule but for synthetic image creation via inputOptions.create. When create.pageHeight is provided, create.height must be an exact multiple of it because created multi-page images are internally laid out as stacked equal pages. The check is `create.height % create.pageHeight !== 0` after confirming pageHeight is a positive integer not exceeding height.

Source

Thrown at lib/input.mjs:343

        throw is.invalidParameterError('jp2.oneshot', 'boolean', inputOptions.jp2.oneshot);
      }
    }
    // Create new image
    if (is.defined(inputOptions.create)) {
      if (
        is.object(inputOptions.create) &&
        is.integer(inputOptions.create.width) && is.inRange(inputOptions.create.width, 1, 100000000) &&
        is.integer(inputOptions.create.height) && is.inRange(inputOptions.create.height, 1, 100000000) &&
        is.integer(inputOptions.create.channels)
      ) {
        inputDescriptor.createWidth = inputOptions.create.width;
        inputDescriptor.createHeight = inputOptions.create.height;
        inputDescriptor.createChannels = inputOptions.create.channels;
        inputDescriptor.createPageHeight = 0;
        if (is.defined(inputOptions.create.pageHeight)) {
          if (is.integer(inputOptions.create.pageHeight) && inputOptions.create.pageHeight > 0 && inputOptions.create.pageHeight <= inputOptions.create.height) {
            if (inputOptions.create.height % inputOptions.create.pageHeight !== 0) {
              throw new Error(`Expected create.height ${inputOptions.create.height} to be a multiple of create.pageHeight ${inputOptions.create.pageHeight}`);
            }
            inputDescriptor.createPageHeight = inputOptions.create.pageHeight;
          } else {
            throw is.invalidParameterError('create.pageHeight', 'positive integer', inputOptions.create.pageHeight);
          }
        }
        // Noise
        if (is.defined(inputOptions.create.noise)) {
          if (!is.object(inputOptions.create.noise)) {
            throw new Error('Expected noise to be an object');
          }
          if (inputOptions.create.noise.type !== 'gaussian') {
            throw new Error('Only gaussian noise is supported at the moment');
          }
          inputDescriptor.createNoiseType = inputOptions.create.noise.type;
          if (!is.inRange(inputOptions.create.channels, 1, 4)) {
            throw is.invalidParameterError('create.channels', 'number between 1 and 4', inputOptions.create.channels);
          }

View on GitHub (pinned to 56676c6918)

Solutions

  1. Set create.height = create.pageHeight * desiredPageCount (e.g., pageHeight 50, height 150 for 3 pages).
  2. For a single-page created image, omit pageHeight entirely.
  3. Validate the divisibility before constructing the options object.

Example fix

// before
sharp({ create: { width: 100, height: 100, channels: 3, background: 'red', pageHeight: 30 } })

// after
sharp({ create: { width: 100, height: 90, channels: 3, background: 'red', pageHeight: 30 } })
Defensive patterns

Strategy: validation

Validate before calling

function createPages({ width, pageHeight, pages, channels, background }) {
  const height = pageHeight * pages;
  if (height % pageHeight !== 0) throw new Error('create.height must be a multiple of create.pageHeight');
  return sharp({ create: { width, height, channels, background, pageHeight } });
}

Type guard

function createHeightDividesPageHeight(create) {
  return Number.isInteger(create.height) && Number.isInteger(create.pageHeight) && create.height % create.pageHeight === 0;
}

Prevention

When it happens

Trigger: sharp({ create: { width: 100, height: 100, channels: 3, background: 'red', pageHeight: 30 } }) — 100 % 30 != 0. Setting pageHeight to a non-divisor while intending N equal pages.

Common situations: Generating placeholder animation frames where the per-frame height was rounded. Confusing pageHeight with a margin/padding concept. Setting pageHeight less than height intending a crop rather than a page split.

Related errors


AI-assisted analysis of lovell/sharp@56676c6918 (2026-08-13). Data as JSON: /api/errors/2c57e500bed00dc9. Report an issue: GitHub.