zapal-tech

payload blurhash plugin

by zapal-tech
Media & images
v1
v2
^1.7.2 || ^2.0.0
MIT

Overview

Summary generated from the README

Adds a readonly blurhash field to upload-enabled collections and fills it automatically when an image is uploaded. It is configured through the plugins array in the Payload config with a list of collection slugs. Works with Payload 1.7.2 or newer, with 2.0.0 or newer recommended. Generation for image sizes is not supported yet.

Features

  • Generates a readonly blurhash field for each uploaded image
  • Enable per upload collection by slug
  • Configurable resize width and height before encoding
  • Configurable X and Y component counts for the encoder
  • Enabled flag to switch the plugin on or off conditionally

Use cases

  • Show lightweight blurred placeholders while images load on a Next.js frontend
  • Improve perceived page speed for image-heavy blogs or team pages

From the author

Dead simple BlurHash auto generation plugin for Payload CMS

Installation

npm i @zapal/payload-blurhash-plugin

8

Stars

0

Forks

1

Open Issues

2 years ago

Last Updated

35

Weekly Downloads

v1.0.7

npm Version

43.0 KB

Unpacked Size

1

Dependencies

GitHub stars

80 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20268
Dec 4, 20268
Dec 3, 20268
Dec 2, 20268
Dec 1, 20268
Nov 30, 20268
Nov 29, 20268
Nov 28, 20268
Nov 27, 20268
Nov 26, 20268
Nov 25, 20268
Nov 24, 20268
Nov 23, 20268
Nov 22, 20268
Nov 21, 20268
Nov 20, 20268
Nov 19, 20268
Nov 18, 20268
Nov 17, 20268
Nov 16, 20268
Nov 15, 20268
Nov 14, 20268
Nov 13, 20268
Nov 12, 20268
Nov 11, 20268
Nov 10, 20268
Nov 9, 20268
Nov 8, 20268
Nov 7, 20268
Nov 6, 20268
Nov 5, 20268
Nov 4, 20268
Nov 3, 20268
Nov 2, 20268
Nov 1, 20268
Oct 31, 20268
Oct 30, 20268
Oct 29, 20268
Oct 28, 20268
Oct 27, 20268
Oct 26, 20268
Oct 25, 20268
Oct 24, 20268
Oct 23, 20268
Oct 22, 20268
Oct 21, 20268
Oct 20, 20268
Oct 19, 20268
Oct 18, 20268
Oct 17, 20268
Oct 16, 20268
Oct 15, 20268
Oct 14, 20268
Oct 13, 20268
Oct 12, 20268
Oct 11, 20268
Oct 10, 20268
Oct 9, 20268
Oct 8, 20268
Oct 7, 20268
Oct 6, 20268
Oct 5, 20268
Oct 4, 20268
Oct 3, 20268
Oct 2, 20268
Oct 1, 20268
Sep 30, 20268
Sep 29, 20268
Sep 28, 20268
Sep 27, 20268
Sep 26, 20268
Sep 25, 20268
Sep 24, 20268
Sep 23, 20268
Sep 22, 20268
Sep 21, 20268
Sep 20, 20268
Sep 19, 20268
Sep 18, 20268
Sep 17, 20268
Sep 16, 20268
Sep 15, 20268
Sep 14, 20268
Sep 13, 20268
Sep 12, 20268
Sep 11, 20268
Sep 10, 20268
Sep 9, 20268
Sep 8, 20268
Sep 7, 20268
Sep 6, 20268
npm weekly downloads

41+25 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202641
Dec 4, 202625
Dec 3, 202625
Dec 2, 202625
Dec 1, 202627
Nov 30, 202627
Nov 29, 202620
Nov 28, 202615
Nov 27, 202614
Nov 26, 202615
Nov 25, 202615
Nov 24, 202613
Nov 23, 202613
Nov 22, 20267
Nov 21, 202615
Nov 20, 202615
Nov 19, 202615
Nov 18, 202623
Nov 17, 202623
Nov 16, 202624
Nov 15, 202624
Nov 14, 202615
Nov 13, 202617
Nov 12, 202615
Nov 11, 20268
Nov 10, 202617
Nov 9, 202616
Nov 8, 202613
Nov 7, 202613
Nov 6, 202611
Nov 5, 202612
Nov 4, 202610
Nov 3, 20263
Nov 2, 20265
Nov 1, 20265
Oct 31, 20267
Oct 30, 20267
Oct 29, 20266
Oct 28, 20266
Oct 27, 20265
Oct 26, 20266
Oct 25, 20267
Oct 24, 202610
Oct 23, 202610
Oct 22, 202611
Oct 21, 202612
Oct 20, 202611
Oct 19, 20268
Oct 18, 20267
Oct 17, 20262
Oct 16, 20262
Oct 15, 20261
Oct 14, 20268
Oct 13, 20268
Oct 12, 20268
Oct 11, 20269
Oct 10, 20269
Oct 9, 202612
Oct 8, 202612
Oct 7, 20265
Oct 6, 20265
Oct 5, 20266
Oct 4, 20265
Oct 3, 20266
Oct 2, 202614
Oct 1, 202614
Sep 30, 202613
Sep 29, 202614
Sep 28, 202614
Sep 27, 202614
Sep 26, 202617
Sep 25, 20266
Sep 24, 20266
Sep 23, 20266
Sep 22, 20268
Sep 21, 202618
Sep 20, 202618
Sep 19, 202614
Sep 18, 202615
Sep 17, 202626
Sep 16, 202628
Sep 15, 202626
Sep 14, 202615
Sep 13, 202620
Sep 12, 202621
Sep 11, 202622
Sep 10, 202613
Sep 9, 202613
Sep 8, 202612
Sep 7, 202615
Sep 6, 202616

Each point is npm's rolling 7-day download count.

Health Score

37/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/706679910-root.svg)](https://payloaddirectory.dev/plugins/706679910-root)
HTML
<a href="https://payloaddirectory.dev/plugins/706679910-root"><img src="https://payloaddirectory.dev/badge/706679910-root.svg" alt="Payload Directory"></a>
Updated Dec 15, 2023Created Oct 18, 2023Published Oct 22, 2023

README

Payload CMS BlurHash Plugin by Zapal

Turbocharge your website performance by creating ultralight image placeholders, resulting in a smoother user experience.

📋 Requirements

  • Payload version 1.7.2 or higher is required (version 2.0.0 or higher is recommended)

🚀 Getting started

Instal the package with yarn add @zapal/payload-blurhash-plugin or npm install @zapal/payload-blurhash-plugin

Now setup the plugin within your payload.config.ts file as follows:

import { buildConfig } from 'payload/config';

import { blurHash } from '@zapal/payload-blurhash-plugin';
import path from 'path';

/* ... */

export default buildConfig({
  plugins: [
    blurHash({
      collections: ['team-photos-collection', 'blog-images-collection'],
    }),
  ],
  /* ... */
});

The plugin will generate a readonly blurhash field for each image uploaded to the specified collections. Generation for imageSizes are not supported yet (but it's in progress).

🎛️ Conditionally enabling/disabling

The proper way to conditionally enable/disable this plugin is to use the enabled property.

blurHash({
  enabled: process.env.ENABLE_BLURHASH_PLUGIN === 'true',
  collections: ['team-photos-collection', 'blog-images-collection'],
}),

⚙️ Plugin options

This plugin is configurable to work across upload-enabled Payload collections. A * denotes that the property is required.

OptionTypeDescription
collections *string[]Array of upload-enabled collections' slugs you want to enable the plugin for.
enabledbooleanConditionally enable/disable plugin. Default: true.
widthnumberWidth to resize the image before computing the blurhash. Default: 32.
heightnumberHeight to resize the image before computing the blurhash. Default: 32.
componentXnumberX component count to pass to the blurhash encoder. Default: 3.
componentYnumberY component count to pass to the blurhash encoder. Default: 3.

See more information about the width, height, componentX, componentY options and BlurHash encoder here.

💻 Local development

You can find the source code in the src directory. For development purposes, you can use the dev directory with all the necessary files to test the plugin in a Payload project. Also we are strongly recommending to use your IDE debugger instead of console.log statements.

You need to follow these steps to start developing and testing the plugin locally:

  1. Go to dev directory (cd dev)
  2. Create .env file (cp .env.example .env)
  3. Setup environment variables in .env file
  4. Install dependencies (npm i)
  5. Run the project (npm run dev)

And you are ready to go!

🤝 Contributing

We are open to, and grateful for, any contributions made by the community.

We are planning to add more features to this plugin in the future. If you have any ideas, create an issue to discuss it.

Next steps (v1):

  • Optional blurhash generation for imageSizes (in progress)
  • Custom field name support
  • Unit tests
  • Code refactoring

Next steps (v2):

  • Custom options for each collection

🛡️ License

This project is licensed under the MIT License

⭐ Like what we're doing? Give us a star

Similar plugins