Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(gatsby-plugin-image): Add docs for customizing default options #30344

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/docs/how-to/images-and-media/using-gatsby-plugin-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,40 @@ If you need to have dynamic images (such as if they are coming from a CMS), you
`
```

## Customizing the defaults

You might find yourself using the same options (like `placeholder`, `formats` etc.) with most of your `GatsbyImage` and `StaticImage` instances.
You can customize the default options with `gatsby-plugin-sharp`.

The following configuration describes the options that can be customized along with their default values:

```javascript:title=gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-sharp`,
options: {
defaults: {
formats: [`auto`, `webp`],
placeholder: `dominantColor`
quality: 50
breakpoints: [750, 1080, 1366, 1920]
backgroundColor: `transparent`
tracedSVGOptions: {}
blurredOptions: {}
jpgOptions: {}
pngOptions: {}
webpOptions: {}
avifOptions: {}
}
}
},
`gatsby-transformer-sharp`,
`gatsby-plugin-image`,
],
}
```

## Using images from a CMS or CDN

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).
Expand Down
34 changes: 34 additions & 0 deletions docs/docs/reference/built-in-components/gatsby-plugin-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,40 @@ The Gatsby Image plugin uses [sharp](https://sharp.pixelplumbing.org) for image
| `webpOptions` | None | Options to pass to sharp when generating WebP images. |
| `avifOptions` | None | Options to pass to sharp when generating AVIF images. |

## Customizing the default options

You might find yourself using the same options (like `placeholder`, `formats` etc.) with most of your `GatsbyImage` and `StaticImage` instances.
You can customize the default options with `gatsby-plugin-sharp`.

The following configuration describes the options that can be customized along with their default values:

```javascript:title=gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-sharp`,
options: {
defaults: {
formats: [`auto`, `webp`],
placeholder: `dominantColor`
quality: 50
breakpoints: [750, 1080, 1366, 1920]
backgroundColor: `transparent`
tracedSVGOptions: {}
blurredOptions: {}
jpgOptions: {}
pngOptions: {}
webpOptions: {}
avifOptions: {}
}
}
},
`gatsby-transformer-sharp`,
`gatsby-plugin-image`,
],
}
```

## Helper functions

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.
Expand Down
35 changes: 35 additions & 0 deletions packages/gatsby-plugin-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ For full documentation on all configuration options, see [the Gatsby Image Plugi
- [Using the Gatsby Image components](#using-the-gatsby-image-components)
- [Static images](#static-images)
- [Dynamic images](#dynamic-images)
- [Customizing the default options](#customizing-the-default-options)
- [Migrating to gatsby-plugin-image](#migrating)

## Installation
Expand Down Expand Up @@ -191,6 +192,40 @@ If you need to have dynamic images (such as if they are coming from a CMS), you

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

## Customizing the default options

You might find yourself using the same options (like `placeholder`, `formats` etc.) with most of your `GatsbyImage` and `StaticImage` instances.
You can customize the default options with `gatsby-plugin-sharp`.

The following configuration describes the options that can be customized along with their default values:

```javascript:title=gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-sharp`,
options: {
defaults: {
formats: [`auto`, `webp`],
placeholder: `dominantColor`
quality: 50
breakpoints: [750, 1080, 1366, 1920]
backgroundColor: `transparent`
tracedSVGOptions: {}
blurredOptions: {}
jpgOptions: {}
pngOptions: {}
webpOptions: {}
avifOptions: {}
}
}
},
`gatsby-transformer-sharp`,
`gatsby-plugin-image`,
],
}
```

## Migrating

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