Skip to content

Commit

Permalink
fix(gatsby-plugin-sharp): ignore incorrect duotone options (#28999)
Browse files Browse the repository at this point in the history
* fix(gatsby-plugin-sharp): ignore incorrect duotone options

* Update packages/gatsby-plugin-sharp/src/index.js

Co-authored-by: Matt Kane <[email protected]>

* Update index.js

* add warning for invalid duotone options

Co-authored-by: Matt Kane <[email protected]>
Co-authored-by: Laurie <[email protected]>
  • Loading branch information
3 people committed Jan 25, 2021
1 parent f945049 commit 298eb31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/gatsby-plugin-sharp/src/image-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const DEFAULT_BLURRED_IMAGE_WIDTH = 20
const DEFAULT_BREAKPOINTS = [750, 1080, 1366, 1920]

type ImageFormat = "jpg" | "png" | "webp" | "avif" | "" | "auto"

export type FileNode = Node & {
absolutePath?: string
extension: string
Expand Down Expand Up @@ -114,8 +115,15 @@ export async function generateImageData({
const {
fit = `cover`,
cropFocus = sharp.strategy.attention,
duotone,
} = transformOptions

if (duotone && (!duotone.highlight || !duotone.shadow)) {
reporter.warn(
`Invalid duotone option specified for ${file.absolutePath}, ignoring. Please pass an object to duotone with the keys "highlight" and "shadow" set to the corresponding hex values you want to use.`
)
}

const metadata = await getImageMetadata(file, placeholder === `dominantColor`)

if ((args.width || args.height) && layout === `fullWidth`) {
Expand Down
8 changes: 7 additions & 1 deletion packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,13 @@ async function generateBase64({ file, args = {}, reporter }) {

// duotone
if (options.duotone) {
pipeline = await duotone(options.duotone, options.toFormat, pipeline)
if (options.duotone.highlight && options.duotone.shadow) {
pipeline = await duotone(options.duotone, options.toFormat, pipeline)
} else {
reporter.warn(
`Invalid duotone option specified for ${file.absolutePath}, ignoring. Please pass an object to duotone with the keys "highlight" and "shadow" set to the corresponding hex values you want to use.`
)
}
}
let buffer
let info
Expand Down

0 comments on commit 298eb31

Please sign in to comment.