Skip to content

Commit

Permalink
fix(gatsby-plugin-sharp): Ensure min 1px height for BLURRED placeho…
Browse files Browse the repository at this point in the history
…lder (#35914)

Co-authored-by: Lennart <lekoarts@gmail.com>
  • Loading branch information
ThomasVandenhede and LekoArts committed Jul 26, 2022
1 parent ae5adb4 commit abad94f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions packages/gatsby-plugin-sharp/src/__tests__/index.js
Expand Up @@ -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`, () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/gatsby-plugin-sharp/src/image-data.ts
Expand Up @@ -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,
})
Expand Down

0 comments on commit abad94f

Please sign in to comment.