Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gatsby-sharp

Package Overview
Dependencies
Maintainers
1
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-sharp

Wrapper of the Sharp image manipulation library for Gatsby plugins

  • 1.0.0-alpha11-alpha.9e7a535a
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
370K
decreased by-8.35%
Maintainers
1
Weekly downloads
 
Created

What is gatsby-sharp?

gatsby-sharp is a Gatsby plugin that provides image processing capabilities using the Sharp image processing library. It allows you to perform various image transformations such as resizing, cropping, and creating responsive images with ease.

What are gatsby-sharp's main functionalities?

Resize Images

This feature allows you to resize images to a specified width while maintaining the aspect ratio. The code sample demonstrates how to query for images and resize them to a maximum width of 800 pixels.

const { fluid } = require('gatsby-sharp');

exports.createPages = async ({ graphql, actions }) => {
  const { createPage } = actions;
  const result = await graphql(`
    {
      allFile {
        edges {
          node {
            childImageSharp {
              fluid(maxWidth: 800) {
                ...GatsbyImageSharpFluid
              }
            }
          }
        }
      }
    }
  `);

  result.data.allFile.edges.forEach(({ node }) => {
    createPage({
      path: `/image/${node.childImageSharp.fluid.src}`,
      component: require.resolve('./src/templates/image.js'),
      context: {
        fluidImage: node.childImageSharp.fluid
      }
    });
  });
};

Crop Images

This feature allows you to crop images to specified dimensions. The code sample demonstrates how to query for images and crop them to a width and height of 400 pixels.

const { fixed } = require('gatsby-sharp');

exports.createPages = async ({ graphql, actions }) => {
  const { createPage } = actions;
  const result = await graphql(`
    {
      allFile {
        edges {
          node {
            childImageSharp {
              fixed(width: 400, height: 400) {
                ...GatsbyImageSharpFixed
              }
            }
          }
        }
      }
    }
  `);

  result.data.allFile.edges.forEach(({ node }) => {
    createPage({
      path: `/image/${node.childImageSharp.fixed.src}`,
      component: require.resolve('./src/templates/image.js'),
      context: {
        fixedImage: node.childImageSharp.fixed
      }
    });
  });
};

Create Responsive Images

This feature allows you to create responsive images that adapt to different screen sizes. The code sample demonstrates how to query for images and generate responsive images with a maximum width of 1200 pixels.

const { fluid } = require('gatsby-sharp');

exports.createPages = async ({ graphql, actions }) => {
  const { createPage } = actions;
  const result = await graphql(`
    {
      allFile {
        edges {
          node {
            childImageSharp {
              fluid(maxWidth: 1200) {
                ...GatsbyImageSharpFluid
              }
            }
          }
        }
      }
    }
  `);

  result.data.allFile.edges.forEach(({ node }) => {
    createPage({
      path: `/image/${node.childImageSharp.fluid.src}`,
      component: require.resolve('./src/templates/image.js'),
      context: {
        fluidImage: node.childImageSharp.fluid
      }
    });
  });
};

Other packages similar to gatsby-sharp

Keywords

FAQs

Package last updated on 24 Jan 2017

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