Skip to content

Commit 7378fcf

Browse files
authored
fix(gatsby-plugin-sharp): Pass format-specific options in image-data (#28826)
1 parent b72b5bc commit 7378fcf

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/gatsby-plugin-image/src/babel-helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const SHARP_ATTRIBUTES = new Set([
1212
`maxHeight`,
1313
`quality`,
1414
`avifOptions`,
15-
`jpegOptions`,
15+
`jpgOptions`,
1616
`pngOptions`,
1717
`webpOptions`,
1818
`blurredOptions`,

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,30 @@ export async function generateImageData({
148148
}
149149

150150
let primaryFormat: ImageFormat | undefined
151-
let options: Record<string, unknown> | undefined
152151
if (useAuto) {
153152
primaryFormat = normalizeFormat(metadata.format || file.extension)
154153
} else if (formats.has(`png`)) {
155154
primaryFormat = `png`
156-
options = args.pngOptions
157155
} else if (formats.has(`jpg`)) {
158156
primaryFormat = `jpg`
159-
options = args.jpgOptions
160157
} else if (formats.has(`webp`)) {
161158
primaryFormat = `webp`
162-
options = args.webpOptions
163159
} else if (formats.has(`avif`)) {
164160
reporter.warn(
165161
`Image ${file.relativePath} specified only AVIF format, with no fallback format. This will mean your site cannot be viewed in all browsers.`
166162
)
167163
primaryFormat = `avif`
168-
options = args.webpOptions
169164
}
170165

166+
const optionsMap = {
167+
jpg: args.jpgOptions,
168+
png: args.pngOptions,
169+
webp: args.webpOptions,
170+
avif: args.avifOptions,
171+
}
172+
173+
const options = primaryFormat ? optionsMap[primaryFormat] : undefined
174+
171175
const imageSizes: {
172176
sizes: Array<number>
173177
presentationWidth: number

0 commit comments

Comments
 (0)