Skip to content

Commit

Permalink
fix(gatsby-plugin-sharp): Handle fractional image sizes (#31057) (#31081
Browse files Browse the repository at this point in the history
)

(cherry picked from commit 08dfb37)

Co-authored-by: Matt Kane <matt@gatsbyjs.com>
  • Loading branch information
GatsbyJS Bot and ascorbic committed Apr 27, 2021
1 parent bab3b55 commit 21dc379
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/gatsby-plugin-sharp/src/image-data.ts
Expand Up @@ -236,7 +236,9 @@ export async function generateImageData({
const primaryIndex =
layout === `fullWidth`
? imageSizes.sizes.length - 1 // The largest image
: imageSizes.sizes.findIndex(size => size === imageSizes.unscaledWidth)
: imageSizes.sizes.findIndex(
size => size === Math.round(imageSizes.unscaledWidth)
)

if (primaryIndex === -1) {
reporter.error(
Expand Down
7 changes: 4 additions & 3 deletions packages/gatsby-plugin-sharp/src/plugin-options.js
Expand Up @@ -119,9 +119,11 @@ exports.healOptions = (
// only set width to 400 if neither width nor height is passed
if (options.width === undefined && options.height === undefined) {
options.width = 400
} else if (options.width !== undefined) {
}
if (options.width !== undefined) {
options.width = parseInt(options.width, 10)
} else if (options.height !== undefined) {
}
if (options.height !== undefined) {
options.height = parseInt(options.height, 10)
}

Expand All @@ -141,7 +143,6 @@ exports.healOptions = (
)
}
})

return options
}

Expand Down

0 comments on commit 21dc379

Please sign in to comment.