Skip to content

Commit 4f84533

Browse files
kelvindecostaLekoArtsgatsbybot
authoredMay 6, 2021
docs(gatsby-plugin-image): Add docs for customizing default options (#30344)
Co-authored-by: Lennart <lekoarts@gmail.com> Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
1 parent d0dee0d commit 4f84533

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed
 

‎docs/docs/how-to/images-and-media/using-gatsby-plugin-image.md

+34
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,40 @@ If you need to have dynamic images (such as if they are coming from a CMS), you
192192
`
193193
```
194194

195+
## Customizing the defaults
196+
197+
You might find yourself using the same options (like `placeholder`, `formats` etc.) with most of your `GatsbyImage` and `StaticImage` instances.
198+
You can customize the default options with `gatsby-plugin-sharp`.
199+
200+
The following configuration describes the options that can be customized along with their default values:
201+
202+
```javascript:title=gatsby-config.js
203+
module.exports = {
204+
plugins: [
205+
{
206+
resolve: `gatsby-plugin-sharp`,
207+
options: {
208+
defaults: {
209+
formats: [`auto`, `webp`],
210+
placeholder: `dominantColor`
211+
quality: 50
212+
breakpoints: [750, 1080, 1366, 1920]
213+
backgroundColor: `transparent`
214+
tracedSVGOptions: {}
215+
blurredOptions: {}
216+
jpgOptions: {}
217+
pngOptions: {}
218+
webpOptions: {}
219+
avifOptions: {}
220+
}
221+
}
222+
},
223+
`gatsby-transformer-sharp`,
224+
`gatsby-plugin-image`,
225+
],
226+
}
227+
```
228+
195229
## Using images from a CMS or CDN
196230

197231
Many source plugins have native support for `gatsby-plugin-image`, with images served directly from a content delivery network (CDN). This means that builds are faster, because there is no need download images and process them locally. The query syntax varies according to the plugin, as do the supported transformation features and image formats. Make sure you update to the latest version of the source plugin to ensure there is support. For plugins that are not in this list you can use [dynamic images from `gatsby-transformer-sharp`](#dynamic-images).

‎docs/docs/reference/built-in-components/gatsby-plugin-image.md

+34
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,40 @@ The Gatsby Image plugin uses [sharp](https://sharp.pixelplumbing.org) for image
291291
| `webpOptions` | None | Options to pass to sharp when generating WebP images. |
292292
| `avifOptions` | None | Options to pass to sharp when generating AVIF images. |
293293

294+
## Customizing the default options
295+
296+
You might find yourself using the same options (like `placeholder`, `formats` etc.) with most of your `GatsbyImage` and `StaticImage` instances.
297+
You can customize the default options with `gatsby-plugin-sharp`.
298+
299+
The following configuration describes the options that can be customized along with their default values:
300+
301+
```javascript:title=gatsby-config.js
302+
module.exports = {
303+
plugins: [
304+
{
305+
resolve: `gatsby-plugin-sharp`,
306+
options: {
307+
defaults: {
308+
formats: [`auto`, `webp`],
309+
placeholder: `dominantColor`
310+
quality: 50
311+
breakpoints: [750, 1080, 1366, 1920]
312+
backgroundColor: `transparent`
313+
tracedSVGOptions: {}
314+
blurredOptions: {}
315+
jpgOptions: {}
316+
pngOptions: {}
317+
webpOptions: {}
318+
avifOptions: {}
319+
}
320+
}
321+
},
322+
`gatsby-transformer-sharp`,
323+
`gatsby-plugin-image`,
324+
],
325+
}
326+
```
327+
294328
## Helper functions
295329

296330
There are a number of utility functions to help you work with `gatsbyImageData` objects. We strongly recommend that you do not try to access the internals of these objects directly, as the format could change.

‎packages/gatsby-plugin-image/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ For full documentation on all configuration options, see [the Gatsby Image Plugi
1010
- [Using the Gatsby Image components](#using-the-gatsby-image-components)
1111
- [Static images](#static-images)
1212
- [Dynamic images](#dynamic-images)
13+
- [Customizing the default options](#customizing-the-default-options)
1314
- [Migrating to gatsby-plugin-image](#migrating)
1415

1516
## Installation
@@ -189,6 +190,40 @@ If you need to have dynamic images (such as if they are coming from a CMS), you
189190

190191
For full APIs, see [Gatsby Image plugin reference guide](https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-plugin-image).
191192

193+
## Customizing the default options
194+
195+
You might find yourself using the same options (like `placeholder`, `formats` etc.) with most of your `GatsbyImage` and `StaticImage` instances.
196+
You can customize the default options with `gatsby-plugin-sharp`.
197+
198+
The following configuration describes the options that can be customized along with their default values:
199+
200+
```javascript:title=gatsby-config.js
201+
module.exports = {
202+
plugins: [
203+
{
204+
resolve: `gatsby-plugin-sharp`,
205+
options: {
206+
defaults: {
207+
formats: [`auto`, `webp`],
208+
placeholder: `dominantColor`
209+
quality: 50
210+
breakpoints: [750, 1080, 1366, 1920]
211+
backgroundColor: `transparent`
212+
tracedSVGOptions: {}
213+
blurredOptions: {}
214+
jpgOptions: {}
215+
pngOptions: {}
216+
webpOptions: {}
217+
avifOptions: {}
218+
}
219+
}
220+
},
221+
`gatsby-transformer-sharp`,
222+
`gatsby-plugin-image`,
223+
],
224+
}
225+
```
226+
192227
## Migrating
193228

194229
_Main article: **[Migrating from gatsby-image to gatsby-plugin-image](https://www.gatsbyjs.com/docs/reference/release-notes/image-migration-guide)**_

0 commit comments

Comments
 (0)
Please sign in to comment.