Skip to content

Commit 08dfb37

Browse files
authored
fix(gatsby-plugin-sharp): Handle fractional image sizes (#31057)
1 parent d036f92 commit 08dfb37

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/gatsby-plugin-sharp/src/image-data.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ export async function generateImageData({
236236
const primaryIndex =
237237
layout === `fullWidth`
238238
? imageSizes.sizes.length - 1 // The largest image
239-
: imageSizes.sizes.findIndex(size => size === imageSizes.unscaledWidth)
239+
: imageSizes.sizes.findIndex(
240+
size => size === Math.round(imageSizes.unscaledWidth)
241+
)
240242

241243
if (primaryIndex === -1) {
242244
reporter.error(

packages/gatsby-plugin-sharp/src/plugin-options.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ exports.healOptions = (
119119
// only set width to 400 if neither width nor height is passed
120120
if (options.width === undefined && options.height === undefined) {
121121
options.width = 400
122-
} else if (options.width !== undefined) {
122+
}
123+
if (options.width !== undefined) {
123124
options.width = parseInt(options.width, 10)
124-
} else if (options.height !== undefined) {
125+
}
126+
if (options.height !== undefined) {
125127
options.height = parseInt(options.height, 10)
126128
}
127129

@@ -141,7 +143,6 @@ exports.healOptions = (
141143
)
142144
}
143145
})
144-
145146
return options
146147
}
147148

0 commit comments

Comments
 (0)