packages/gatsby-transformer-sqip/README.md
Generates vectorized primitive version of images to be used as preview thumbnails.
This project can create beautiful results, but this comes with the cost of processing power. It may take several seconds on your machine to generate the preview. Make sure to invest some time and to cache your public folder to avoid regeneration of the previews on every build.
With gatsby-transformer-sharp:
image {
sqip(numberOfPrimitives: 12, blur: 12, width: 256, height: 256) {
dataURI
},
fluid(maxWidth: 400, maxHeight: 400) {
...GatsbyImageSharpFluid_noBase64
}
}
With gatsby-source-contentful:
image {
sqip(numberOfPrimitives: 30, blur: 0) {
dataURI
},
fixed {
...GatsbyContentfulFixed_withWebp_noBase64
}
}
numberOfPrimitives: Integer, default: 10Number of primitive shapes of the image. This has a strong impact on the resulting size of the image. See below for more information.
mode: Integer, default: 0Determines which type of shapes are used to generate the image.
blur: Integer, default: 1Blur factor of the image. Reflects the deviation value of the SVG Gaussian Blur filter. 0 disables the blur completely.
width: Integer, default: 256Width of the input image, which is used to generate the preview. 256px is an ideal width which provides enough details and is small enough to ensure a quick generation. It is recommended to keep this value as it is.
height: Integer, default: autoThe 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 sharp/Contentful thumbnails.
grayscale: GraphQLBoolean, default: falseUses Sharp's greyscale to convert the source image to 8-bit greyscale, 256 shades of grey, e.g.
See: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-sharp#grayscale
duotone: DuotoneGradientType, default: falseSee: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-sharp#duotone
cropFocus: ImageCropFocusType, default: sharp.strategy.attentionSee: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-sharp#cropfocus
rotate: GraphQLInt, default: 0See: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-sharp#rotate
resizingBehavior: ImageResizingBehaviorcropFocus: ImageCropFocusType, default: nullbackground: GraphQLString, default: null<div className="image-wrapper">
</div>
.image-wrapper {
position: relative;
overflow: hidden;
}
.image-wrapper img {
display: block;
}
.image-wrapper img.image {
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 100%;
height: auto;
z-index: 1;
}
Pros:
Cons:
Just use it as usual with the exception that you overwrite the base64 value with your SQIP dataURI.
const Img = require(`gatsby-image`)
// or
Pros:
Cons:
The plugin offers a wide variety of settings, which affect the size of the resulting preview image.
The maximum size of your previews really depend on your current html payload size and your personal limits.
Generally: Keep it as small as possible and test the impact of your image previews via webpagetest.org on a 3G connection.
You may use my research repository for more detailed insights on how much the configuration can affect your payload size: https://axe312ger.github.io/embedded-svg-loading-impact-research/