# GatsbyImage

https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-plugin-image


## `gatsby-plugin-image`

- use with `import { GatsbyImage, getImage, getSrc } from "gatsby-plugin-image"`
- also relies on a custom `gatsbyImageData` resolver, which is available if the plugin is included in `gatsby-config.js`
- `getImage` and `getSrc` return a full object, and the src value respectively from the resolved data
- [API is described here](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-image/README.md#gatsbyimage)

## `gatsbyImageData()` resolver options

NB. the following excludes sharp's `transformOptions`

|option|values|meaning|
|--|--|--|
|width|integer|The display width of the generated image. The actual largest image resolution will be this value multipled by the largest value in outputPixelDensities. Ignored if layout = FLUID or CONSTRAINED, where you should use "maxWidth" instead.
|height|integer|If set, the height of the generated image. If omitted, it is calculated from the supplied width, matching the aspect ratio of the source image.
|maxWidth|integer|Maximum display width of generated files. The actual largest image resolution will be this value multipled by the largest value in outputPixelDensities This only applies when layout = FLUID or CONSTRAINED. For other layout types, use "width"
|maxHeight|integer|If set, the generated image is a maximum of this height, cropping if necessary. If the image layout is "constrained" then the image will be limited to this height. If the aspect ratio of the image is different than the source, then the image will be cropped.`,
|placeholder|`BLURRED|TRACED_SVG|DOMINANT_COLOR`|Format of generated placeholder image. BLURRED: (default) a blurred, low resolution image, encoded as a base64 data URI TRACED_SVG: a low-resolution traced SVG of the image. NONE: no placeholder. Set "background" to use a fixed background color. DOMINANT_COLOR: a solid color, calculated from the dominant color of the image.
|layout|`FIXED|FLUID|CONSTRAINED`|The layout for the image. FIXED: (default) A static image size, that does not resize according to the screen width FLUID: The image resizes to fit its container. Pass a "sizes" option if it isn't going to be the full width of the screen. CONSTRAINED: Resizes to fit its container, up to a maximum width, at which point it will remain fixed in size.
|outputPixelDensities|array of floats|A list of image pixel densities to generate. It will never generate images larger than the source, and will always include a 1x image. Default is [ 1, 2 ] for fixed images, meaning 1x, 2x and [0.25, 0.5, 1, 2] for fluid. In this case, an image with a fluid layout and width = 400 would generate images at 100, 200, 400 and 800px wide
|sizes|integer|The "sizes" property, passed to the img tag. This describes the display size of the image. This does not affect the generated images, but is used by the browser to decide which images to download. You can leave this blank for fixed images, or if the responsive image container will be the full width of the screen. In these cases we will generate an appropriate value.
|formats|array of strings|an array of file formats to generate. The default is `[AUTO, WEBP]`, which means it will generate images in the same format as the source image, as well as in the next-generation WebP format. We strongly recommend you do not change this option, as doing so will affect performance scores.
|quality|integer|The default quality. This is overriden by any format-specific options
|background|color name string?|Background color applied to the wrapper. Also passed to sharp to use as a background when "letterboxing" an image to another aspect ratio.
|blurredOptions|`{ width, toFormat }`|Options for the low-resolution placeholder image. Set placeholder to "BLURRED" to use this
|tracedSVGOptions||Options for traced placeholder SVGs. You also should set placeholder to "SVG".
|jpgOptions|`{ quality, progressive }`|Options to pass to sharp when generating JPG images.
|pngOptions|`{ quality, compressionSpeed }`|Options to pass to sharp when generating PNG images.
|webpOptions|`{ quality }`|Options to pass to sharp when generating WebP images.
