Skip to content

Commit

Permalink
feat(gatsby-plugin-sharp): Support base64Width as a config option
Browse files Browse the repository at this point in the history
Allows setting a project wide default, rather than having to request it per image.

Updates `defaultBase64Width` to be a function as `pluginOptions` has not initialized when assigned.
  • Loading branch information
polarathene authored Jan 14, 2019
1 parent 4b25461 commit b100584
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,10 @@ function queueImageResizing({ file, args = {}, reporter }) {
}
}

const defaultBase64Width = 20 // A value in pixels(Int)
// A value in pixels(Int)
const defaultBase64Width = () => pluginOptions.base64Width || 20
async function generateBase64({ file, args, reporter }) {
const options = healOptions(args, { width: defaultBase64Width })
const options = healOptions(args, { width: defaultBase64Width() })
let pipeline
try {
pipeline = sharp(file.absolutePath).rotate()
Expand Down Expand Up @@ -679,7 +680,7 @@ async function fluid({ file, args = {}, reporter, cache }) {
})
})

const base64Width = options.base64Width || defaultBase64Width
const base64Width = options.base64Width || defaultBase64Width()
const base64Height = Math.max(1, Math.round((base64Width * height) / width))
const base64Args = {
duotone: options.duotone,
Expand Down

0 comments on commit b100584

Please sign in to comment.