{"record":{"id":"832cbe08d4d87475","repo":"gatsbyjs/gatsby","slug":"specified-dimensions-for-images-must-be-positive-n","errorCode":null,"errorMessage":"Specified dimensions for images must be positive numbers (> 0). Problem dimensions you have are ${erroneousUserDimensions.map(dim => dim.join(`: `)).join(`, `)}","messagePattern":"Specified dimensions for images must be positive numbers \\(> 0\\)\\. Problem dimensions you have are (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-image/src/image-utils.ts","lineNumber":384,"sourceCode":"\nexport function calculateImageSizes(args: IImageSizeArgs): IImageSizes {\n  const {\n    width,\n    height,\n    filename,\n    layout = `constrained`,\n    sourceMetadata: imgDimensions,\n    reporter = { warn },\n    breakpoints = DEFAULT_BREAKPOINTS,\n  } = args\n\n  // check that all dimensions provided are positive\n  const userDimensions = { width, height }\n  const erroneousUserDimensions = Object.entries(userDimensions).filter(\n    ([_, size]) => typeof size === `number` && size < 1\n  )\n  if (erroneousUserDimensions.length) {\n    throw new Error(\n      `Specified dimensions for images must be positive numbers (> 0). Problem dimensions you have are ${erroneousUserDimensions\n        .map(dim => dim.join(`: `))\n        .join(`, `)}`\n    )\n  }\n\n  if (layout === `fixed`) {\n    return fixedImageSizes(args)\n  } else if (layout === `constrained`) {\n    return responsiveImageSizes(args)\n  } else if (layout === `fullWidth`) {\n    return responsiveImageSizes({ breakpoints, ...args })\n  } else {\n    reporter.warn(\n      `No valid layout was provided for the image at ${filename}. Valid image layouts are fixed, fullWidth, and constrained. Found ${layout}`\n    )\n    return {\n      sizes: [imgDimensions.width],","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-image/src/image-utils.ts#L366-L402","documentation":"Thrown by calculateImageSizes in gatsby-plugin-image when any user-supplied `width` or `height` is a number less than 1. The pipeline filters dimensions for `typeof size === 'number' && size < 1` and reports each offending pair; negative or zero sizes would break downstream size math, so they are rejected up front.","triggerScenarios":"Passing width=0, width=-200, height=0, or fractional sub-pixel values to calculateImageSizes/generateImageData (e.g. via the <GatsbyImage> component's width/height or the GraphQL gatsbyImageData arguments). Any one bad dimension triggers the throw.","commonSituations":"Computing width/height from a CMS field that occasionally returns 0 for an empty image; passing a CSS-derived fractional pixel value; typos negating a dimension; responsive math producing 0 for tiny viewports.","solutions":["Coerce or clamp dimensions to a minimum of 1 before passing them in.","Trace where the 0/negative value originates (CMS, query, computed ratio) and fix the source.","If the dimension is genuinely unknown, omit it and let sourceMetadata drive sizing.","Add a guard in your GraphQL resolver or component to fall back to a default when width/height is invalid."],"exampleFix":"// before\n<GatsbyImage image={getImage({ ...data, width: 0 })} />\n// after\nconst w = userWidth && userWidth > 0 ? userWidth : undefined\n<GatsbyImage image={getImage({ ...data, width: w })} />","handlingStrategy":"validation","validationCode":"const dims = { width, height }\nfor (const [k, v] of Object.entries(dims)) {\n  if (typeof v === 'number' && v < 1) delete dims[k] // let sourceMetadata size instead\n}","typeGuard":"const arePositiveDimensions = (w?: number, h?: number): boolean =>\n  (typeof w !== 'number' || w >= 1) && (typeof h !== 'number' || h >= 1)","tryCatchPattern":null,"preventionTips":["Clamp width/height to a minimum of 1 before passing to image APIs.","Omit unknown dimensions rather than passing 0.","Guard CMS-derived fields that may return 0."],"tags":["gatsby-plugin-image","validation","dimensions","image-processing"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}