Gathering detailed insights and metrics for gatsby-plugin-image
Gathering detailed insights and metrics for gatsby-plugin-image
Gathering detailed insights and metrics for gatsby-plugin-image
Gathering detailed insights and metrics for gatsby-plugin-image
gatsby-plugin-sharp
Wrapper of the Sharp image manipulation library for Gatsby plugins
gatsby-transformer-sharp
Gatsby transformer plugin for images using Sharp
gatsby-remark-images
Processes images in markdown so they can be used in the production build.
gatsby-plugin-remote-images
Gatsby plugin to use gatsby-image on remote images from absolute path string fields on other nodes.
The best React-based framework with performance, scalability and security built in.
npm install gatsby-plugin-image
Typescript
Module System
Node Version
NPM Version
gatsby-source-shopify@9.0.0
Updated on Jan 07, 2025
gatsby-link@5.14.1
Updated on Jan 07, 2025
gatsby-source-contentful@8.15.0
Updated on Jan 07, 2025
v5.14.0
Updated on Nov 06, 2024
gatsby-source-shopify@8.13.2
Updated on Oct 28, 2024
gatsby-source-wordpress@7.13.5 and 6 more...
Updated on Oct 28, 2024
JavaScript (58.91%)
TypeScript (38.71%)
CSS (1.05%)
HTML (0.69%)
MDX (0.45%)
Shell (0.13%)
Dockerfile (0.03%)
PHP (0.02%)
EJS (0.01%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
55,905 Stars
21,738 Commits
10,289 Forks
719 Watchers
316 Branches
3,966 Contributors
Updated on Jul 14, 2025
Latest Version
3.14.0
Package Id
gatsby-plugin-image@3.14.0
Unpacked Size
631.85 kB
Size
162.22 kB
File Count
87
NPM Version
lerna/3.22.1/node@v20.11.1+arm64 (darwin)
Node Version
20.11.1
Published on
Nov 06, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
14
23
Adding responsive images to your site while maintaining high performance scores can be difficult to do manually. The Gatsby Image plugin handles the hard parts of producing images in multiple sizes and formats for you!
For full documentation on all configuration options, see the Gatsby Image Plugin reference guide
gatsby-plugin-image
and gatsby-plugin-sharp
. Additionally install gatsby-source-filesystem
if you are using static images, and gatsby-transformer-sharp
if you are using dynamic images.1npm install gatsby-plugin-image gatsby-plugin-sharp gatsby-source-filesystem gatsby-transformer-sharp
gatsby-config.js
:1module.exports = { 2 plugins: [ 3 `gatsby-plugin-image`, 4 `gatsby-plugin-sharp`, 5 `gatsby-transformer-sharp`, // Needed for dynamic images 6 ], 7}
The Gatsby Image plugin includes two image components: one for static and one for dynamic images. An effective way to decide which you need is to ask yourself: "will this image be the same every time the component or template is used?". If it will always be the same, then use StaticImage
. If it will change, whether through data coming from a CMS or different values passed to a component each time you use it, then it is a dynamic image and you should use the GatsbyImage
component.
If you are using an image that will be the same each time the component is used, such as a logo or front page hero image, you can use the StaticImage
component. The image can be a local file in your project or an image hosted on a remote server. Any remote images are downloaded and resized at build time.
Add the image to your project.
If you are using a local image, copy it into the project. A folder such as src/images
is a good choice.
Add the StaticImage
component to your template.
Import the component, then set the src
prop to point to the image you added earlier. The path is relative to the source file itself. If your component file was src/components/dino.js
, then you would load the image like this:
1import { StaticImage } from "gatsby-plugin-image" 2 3export function Dino() { 4 return <StaticImage src="../images/dino.png" alt="A dinosaur" /> 5}
If you are using a remote image, pass the image URL in the src
prop:
1import { StaticImage } from "gatsby-plugin-image" 2 3export function Kitten() { 4 return <StaticImage src="https://placekitten.com/800/600" alt="A kitten" /> 5}
When you build your site, the StaticImage
component will load the image from your filesystem or from the remote URL, and it will generate all the sizes and formats that you need to support a responsive image.
Because the image is loaded at build time, you cannot pass the filename in as a prop, or otherwise generate it outside of the component. It should either be a static string, or a local variable in the component's scope.
Important: Remote images are downloaded and resized at build time. If the image is changed on the other server, it will not be updated on your site until you rebuild.
Configure the image.
You configure the image by passing props to the <StaticImage />
component. You can change the size and layout, as well as settings such as the type of placeholder used when lazy loading. There are also advanced image processing options available. You can find the full list of options in the API docs.
1import { StaticImage } from "gatsby-plugin-image" 2 3export function Dino() { 4 return ( 5 <StaticImage 6 src="../images/dino.png" 7 alt="A dinosaur" 8 placeholder="blurred" 9 layout="fixed" 10 width={200} 11 height={200} 12 /> 13 ) 14}
This component renders a 200px by 200px image of a dinosaur. Before loading it will have a blurred, low-resolution placeholder. It uses the "fixed"
layout, which means the image does not resize with its container.
StaticImage
There are a few technical restrictions to the way you can pass props into StaticImage
. Most importantly, you can't use any of the parent component's props. For more information, refer to the Gatsby Image plugin reference guide. If you find yourself wishing you could use a prop passed from a parent for the image src
then it's likely that you should be using a dynamic image.
If you need to have dynamic images (such as if they are coming from a CMS), you can load them via GraphQL and display them using the GatsbyImage
component.
Add the image to your page query.
Any GraphQL File object that includes an image will have a childImageSharp
field that you can use to query the image data. The exact data structure will vary according to your data source, but the syntax is like this:
1query { 2 blogPost(id: { eq: $Id }) { 3 title 4 body 5 avatar { 6 childImageSharp { 7 gatsbyImageData(width: 200) 8 } 9 } 10 } 11}
Configure your image.
For all the configuration options, see the Gatsby Image plugin reference guide.
You configure the image by passing arguments to the gatsbyImageData
resolver. You can change the size and layout, as well as settings such as the type of placeholder used when lazy loading. There are also advanced image processing options available. You can find the full list of options in the API docs.
1query { 2 blogPost(id: { eq: $Id }) { 3 title 4 body 5 author 6 avatar { 7 childImageSharp { 8 gatsbyImageData( 9 width: 200 10 placeholder: BLURRED 11 formats: [AUTO, WEBP, AVIF] 12 ) 13 } 14 } 15 } 16}
Display the image.
You can then use the GatsbyImage
component to display the image on the page. The getImage()
function is an optional helper to make your code easier to read. It takes a File
and returns file.childImageSharp.gatsbyImageData
, which can be passed to the GatsbyImage
component.
1import { graphql } from "gatsby" 2import { GatsbyImage, getImage } from "gatsby-plugin-image" 3 4function BlogPost({ data }) { 5 const image = getImage(data.blogPost.avatar) 6 return ( 7 <section> 8 <h2>{data.blogPost.title}</h2> 9 <GatsbyImage image={image} alt={data.blogPost.author} /> 10 <p>{data.blogPost.body}</p> 11 </section> 12 ) 13} 14 15export const pageQuery = graphql` 16 query { 17 blogPost(id: { eq: $Id }) { 18 title 19 body 20 author 21 avatar { 22 childImageSharp { 23 gatsbyImageData( 24 width: 200 25 placeholder: BLURRED 26 formats: [AUTO, WEBP, AVIF] 27 ) 28 } 29 } 30 } 31 } 32`
For full APIs, see Gatsby Image plugin reference guide.
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:
1module.exports = { 2 plugins: [ 3 { 4 resolve: `gatsby-plugin-sharp`, 5 options: { 6 defaults: { 7 formats: [`auto`, `webp`], 8 placeholder: `dominantColor`, 9 quality: 50, 10 breakpoints: [750, 1080, 1366, 1920], 11 backgroundColor: `transparent`, 12 tracedSVGOptions: {}, 13 blurredOptions: {}, 14 jpgOptions: {}, 15 pngOptions: {}, 16 webpOptions: {}, 17 avifOptions: {}, 18 } 19 } 20 }, 21 `gatsby-transformer-sharp`, 22 `gatsby-plugin-image`, 23 ], 24}
Main article: Migrating from gatsby-image to gatsby-plugin-image
If your site uses the old gatsby-image
component, you can use a codemod to help you migrate to the new Gatsby Image components. This can update the code for most sites. To use the codemod, run this command in the root of your site:
1npx gatsby-codemods gatsby-plugin-image
This will convert all GraphQL queries and components to use the new plugin. For more details, see the migration guide.
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
Found 20/25 approved changesets -- score normalized to 8
Reason
8 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 8
Reason
SAST tool is not run on all commits -- score normalized to 8
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
100 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More