diff --git a/packages/gatsby-plugin-sharp/src/__tests__/images/wide-aspect-ratio.png b/packages/gatsby-plugin-sharp/src/__tests__/images/wide-aspect-ratio.png new file mode 100644 index 0000000000000..c63a28149ffab Binary files /dev/null and b/packages/gatsby-plugin-sharp/src/__tests__/images/wide-aspect-ratio.png differ diff --git a/packages/gatsby-plugin-sharp/src/__tests__/index.js b/packages/gatsby-plugin-sharp/src/__tests__/index.js index 7f8400615b81d..e0713939fa4d2 100644 --- a/packages/gatsby-plugin-sharp/src/__tests__/index.js +++ b/packages/gatsby-plugin-sharp/src/__tests__/index.js @@ -549,6 +549,20 @@ describe(`gatsby-plugin-sharp`, () => { } `) }) + + it(`handles really wide aspect ratios for blurred placeholder`, async () => { + const result = await base64({ + file: getFileObject( + path.join(__dirname, `images/wide-aspect-ratio.png`), + `wide-aspect-ratio`, + `1000x10` + ), + args, + }) + + expect(result.width).toEqual(20) + expect(result.height).toEqual(1) + }) }) describe(`tracedSVG`, () => { diff --git a/packages/gatsby-plugin-sharp/src/image-data.ts b/packages/gatsby-plugin-sharp/src/image-data.ts index 01b3e454e778f..5b6de4cf2e1d3 100644 --- a/packages/gatsby-plugin-sharp/src/image-data.ts +++ b/packages/gatsby-plugin-sharp/src/image-data.ts @@ -375,7 +375,10 @@ export async function generateImageData({ ...options, toFormatBase64: args.blurredOptions?.toFormat, width: placeholderWidth, - height: Math.round(placeholderWidth / imageSizes.aspectRatio), + height: Math.max( + 1, + Math.round(placeholderWidth / imageSizes.aspectRatio) + ), }, reporter, })