npm install @m5r/gatsby-transformer-blurhash
or
yarn add @m5r/gatsby-transformer-blurhash
You will need https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-sharp
to use this plugin.
Add @m5r/gatsby-transformer-blurhash
to your gatsby-config.js
module.exports = {
siteMetadata: {
title: `Gatsby Blurhash Example`,
},
plugins: [
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images/`,
},
},
`gatsby-image`,
`gatsby-plugin-sharp`,
`gatsby-transformer-sharp`,
`@m5r/gatsby-transformer-blurhash`,
],
}
import { graphql } from "gatsby";
import Image from "gatsby-image";
import PropTypes from "prop-types";
const IndexPage = ({ data }) => (
<>
{data.images.edges.map(image => (
<Image
fluid={{
...image.node.childImageSharp.fluid,
base64: image.node.childImageSharp.blurHash.base64Image,
}}
/>
))}
</>
);
export default IndexPage;
IndexPage.propTypes = {
data: PropTypes.object,
};
export const query = graphql`
query {
images: allFile(
filter: { sourceInstanceName: { eq: "images" }, ext: { eq: ".jpg" } }
) {
edges {
node {
publicURL
name
childImageSharp {
fluid(maxWidth: 400, maxHeight: 400) {
...GatsbyImageSharpFluid_noBase64
}
blurHash(width: 400) {
base64Image
}
}
}
}
}
}
`;
See: https://github.com/woltapp/blurhash#how-do-i-pick-the-number-of-x-and-y-components
See: https://github.com/woltapp/blurhash#how-do-i-pick-the-number-of-x-and-y-components
Width of the input image, which is used to generate the preview.
The height of the input image, which is used to generate the preview. By default this value is calculated automatically to keep the aspect ratio of the input image. Make sure to adjust the value to reflect the desired aspect ratio of your generated thumbnails.
See: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-sharp#grayscale
See: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-sharp#duotone
See: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-sharp#cropfocus
See: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-sharp#rotate