@gvrs/gatsby-transformer-blurhash

2.0.0 • Public • Published

@gvrs/gatsby-transformer-blurhash

npm (scoped) NPM PRs Welcome

Generate BlurHash placeholders for images.

Configuration

// In your gatsby-config.js
module.exports = {
  plugins: [
    `gatsby-plugin-image`,
    `gatsby-plugin-sharp`,
    `gatsby-transformer-sharp`,
    `@gvrs/gatsby-transformer-blurhash`,
  ],
};

Usage example

Fetching data

imageSharp {
  gatsbyImageData(
    placeholder: NONE
  )
  blurHash(
    componentX: 3,
    componentY: 4,
    width: 32
  ) {
    base64Image
    hash
  }
}

Rendering

import { GatsbyImage } from "gatsby-plugin-image";

const Image = ({ gatsbyImageData, blurHash }) => (
  <GatsbyImage
    image={{
      ...gatsbyImageData,
      placeholder: {
        fallback: blurHash.base64Image,
      },
    }}
  />
);

Parameters

  • width (int, default: 32)
  • componentX (int, between 1 and 9, default: 3)
  • componentY (int, between 1 and 9, default: 4)

Returns

  • hash (string) — base 83 data returned by BlurHash
  • base64Image (string) — base 64 encoded image

Additional documentation

Prior art, inspiration

See also

/@gvrs/gatsby-transformer-blurhash/

    Package Sidebar

    Install

    npm i @gvrs/gatsby-transformer-blurhash

    Weekly Downloads

    27

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    11.2 kB

    Total Files

    7

    Last publish

    Collaborators

    • alex.gavrusev