Socket
Socket
Sign inDemoInstall

gatsby-plugin-image

Package Overview
Dependencies
Maintainers
6
Versions
399
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-plugin-image

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!


Version published
Weekly downloads
143K
decreased by-2.73%
Maintainers
6
Weekly downloads
 
Created

What is gatsby-plugin-image?

gatsby-plugin-image is a powerful image optimization plugin for Gatsby, a React-based framework. It provides a set of React components and GraphQL fragments to optimize and load images in a performant way, ensuring that images are loaded quickly and efficiently.

What are gatsby-plugin-image's main functionalities?

StaticImage

The StaticImage component is used for static images that are known at build time. It provides a simple way to add optimized images to your site with various layout options like fixed, fluid, and constrained.

import { StaticImage } from 'gatsby-plugin-image';

const MyComponent = () => (
  <StaticImage
    src="../images/my-image.jpg"
    alt="A descriptive alt text"
    placeholder="blurred"
    layout="fixed"
    width={300}
    height={200}
  />
);

GatsbyImage

The GatsbyImage component is used for dynamic images that are queried at runtime. It provides advanced image optimization features and supports various layout options. The getImage helper function is used to extract the image data from the GraphQL query.

import { GatsbyImage, getImage } from 'gatsby-plugin-image';
import { graphql, useStaticQuery } from 'gatsby';

const MyComponent = () => {
  const data = useStaticQuery(graphql`
    query {
      file(relativePath: { eq: "my-image.jpg" }) {
        childImageSharp {
          gatsbyImageData(layout: CONSTRAINED, placeholder: BLURRED, width: 300)
        }
      }
    }
  `);
  const image = getImage(data.file.childImageSharp.gatsbyImageData);
  return <GatsbyImage image={image} alt="A descriptive alt text" />;
};

Image Processing with GraphQL

This feature allows you to use GraphQL to query image data and process it with Sharp, a high-performance image processing library. The queried image data can then be used with the GatsbyImage component to render optimized images.

export const query = graphql`
  query {
    file(relativePath: { eq: "my-image.jpg" }) {
      childImageSharp {
        gatsbyImageData(layout: CONSTRAINED, placeholder: BLURRED, width: 300)
      }
    }
  }
`;

const MyComponent = ({ data }) => {
  const image = getImage(data.file.childImageSharp.gatsbyImageData);
  return <GatsbyImage image={image} alt="A descriptive alt text" />;
};

Other packages similar to gatsby-plugin-image

Keywords

FAQs

Package last updated on 23 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc