@gvrs/gatsby-transformer-image-mask

2.0.0 • Public • Published

@gvrs/gatsby-transformer-image-mask

npm (scoped) NPM PRs Welcome

Refine edges of placeholders with transparent parts

Configuration

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

Usage example

Fetching data

imageSharp {
  gatsbyImageData
  imageMask {
    base64
  }
}

Rendering

import { GatsbyImage } from "gatsby-plugin-image";
import styled from "@emotion/styled";

const GatsbyImageWithMask = styled(GatsbyImage)`
  & [data-placeholder-image] {
    mask-image: url("${(props) => props.mask}");
    mask-size: "contain";
    mask-position: "center center";
    mask-repeat: "no-repeat";
  }
`;

const Image = ({ gatsbyImageData, imageMask }) => (
  <GatsbyImageWithMask image={gatsbyImageData} mask={imageMask.base64} />
);

Returns

  • base64 (string) — base 64 encoded svg mask

Additional documentation

See also

Package Sidebar

Install

npm i @gvrs/gatsby-transformer-image-mask

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

9.2 kB

Total Files

7

Last publish

Collaborators

  • alex.gavrusev