{"record":{"id":"938dd2fbc80ccb25","repo":"lovell/sharp","slug":"expected-raw-height-inputoptions-raw-height-to","errorCode":null,"errorMessage":"Expected raw.height ${inputOptions.raw.height} to be a multiple of raw.pageHeight ${inputOptions.raw.pageHeight}","messagePattern":"Expected raw\\.height (.+?) to be a multiple of raw\\.pageHeight (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/input.mjs","lineNumber":236,"sourceCode":"            inputDescriptor.rawDepth = 'uchar';\n            break;\n        }\n      } else {\n        throw new Error('Expected width, height and channels for raw pixel input');\n      }\n      inputDescriptor.rawPremultiplied = false;\n      if (is.defined(inputOptions.raw.premultiplied)) {\n        if (is.bool(inputOptions.raw.premultiplied)) {\n          inputDescriptor.rawPremultiplied = inputOptions.raw.premultiplied;\n        } else {\n          throw is.invalidParameterError('raw.premultiplied', 'boolean', inputOptions.raw.premultiplied);\n        }\n      }\n      inputDescriptor.rawPageHeight = 0;\n      if (is.defined(inputOptions.raw.pageHeight)) {\n        if (is.integer(inputOptions.raw.pageHeight) && inputOptions.raw.pageHeight > 0 && inputOptions.raw.pageHeight <= inputOptions.raw.height) {\n          if (inputOptions.raw.height % inputOptions.raw.pageHeight !== 0) {\n            throw new Error(`Expected raw.height ${inputOptions.raw.height} to be a multiple of raw.pageHeight ${inputOptions.raw.pageHeight}`);\n          }\n          inputDescriptor.rawPageHeight = inputOptions.raw.pageHeight;\n        } else {\n          throw is.invalidParameterError('raw.pageHeight', 'positive integer', inputOptions.raw.pageHeight);\n        }\n      }\n    }\n    // Multi-page input (GIF, TIFF, PDF)\n    if (is.defined(inputOptions.animated)) {\n      if (is.bool(inputOptions.animated)) {\n        inputDescriptor.pages = inputOptions.animated ? -1 : 1;\n      } else {\n        throw is.invalidParameterError('animated', 'boolean', inputOptions.animated);\n      }\n    }\n    if (is.defined(inputOptions.pages)) {\n      if (is.integer(inputOptions.pages) && is.inRange(inputOptions.pages, -1, 100000)) {\n        inputDescriptor.pages = inputOptions.pages;","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/lovell/sharp/blob/56676c69180a32b468123e090f87bfee30539b49/lib/input.mjs#L218-L254","documentation":"Thrown when raw pixel input specifies a pageHeight that does not evenly divide the total height. Raw multi-page images are represented as a single tall buffer split into equal-sized pages, so height must be an exact multiple of pageHeight; otherwise pages would have unequal sizes and the page boundaries could not be computed. The check is `raw.height % raw.pageHeight !== 0`.","triggerScenarios":"sharp(buf, { raw: { width: 10, height: 100, channels: 4, pageHeight: 30 } }) — 100 is not divisible by 30. Setting pageHeight to a value larger than height also fails earlier with a different error; this specific error is for the in-range but non-divisor case.","commonSituations":"Treating a single-page buffer as multi-page by guessing pageHeight. Mismatch between the actual frame height of an animation and the declared total height. Using pageHeight equal to height for a single page (valid, 1 page) vs an arbitrary value.","solutions":["Choose pageHeight so that height / pageHeight is a whole number (e.g., height 100 with pageHeight 25 yields 4 pages).","For a single-page raw image, either omit pageHeight or set it equal to height.","Recompute total height as pageHeight * numberOfPages and pass that as height."],"exampleFix":"// before\nsharp(buf, { raw: { width: 10, height: 100, channels: 4, pageHeight: 30 } })\n\n// after\nsharp(buf, { raw: { width: 10, height: 90, channels: 4, pageHeight: 30 } }) // 3 pages","handlingStrategy":"validation","validationCode":"function rawPages(buffer, { width, pageHeight, pages, channels }) {\n  const height = pageHeight * pages;\n  if (height % pageHeight !== 0) throw new Error('height must be a multiple of pageHeight');\n  if (buffer.length !== width * height * channels) throw new Error('buffer size mismatch');\n  return sharp(buffer, { raw: { width, height, channels, pageHeight } });\n}","typeGuard":"function rawHeightDividesPageHeight(raw) {\n  return Number.isInteger(raw.height) && Number.isInteger(raw.pageHeight) && raw.height % raw.pageHeight === 0;\n}","tryCatchPattern":null,"preventionTips":["Compute total height as pageHeight * pageCount.","For single-page raw images, omit pageHeight or set it equal to height.","Validate divisibility before building the raw object."],"tags":["raw","input","pageheight","multipage","validation"],"backgroundTag":null,"analyzedSha":"56676c69180a32b468123e090f87bfee30539b49","analyzedAt":"2026-08-13T04:44:31.201Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}