invakid404

payload blurhash plugin

by invakid404
Media & images
v?
v3.0.0-beta.76
Unlicense

Overview

Summary generated from the README

Adds automatic Blurhash encoding for images in Payload upload collections. Registered through the plugins array, it stores a compact placeholder hash for each image. It can use either the blurhash or thumbhash algorithm, and separate package versions exist for Payload v2 and v3.

Features

  • Automatic placeholder hash generation on image upload
  • Choice of blurhash or thumbhash algorithm
  • Configurable blurhash width, height and component counts
  • Limit to specific collections or MIME type patterns
  • Optional display of the hash field in the admin interface

Use cases

  • Show blurred image placeholders while full images load on a frontend
  • Add low-quality image previews to existing media collections without manual work

From the author

Payload CMS plugin for automatic Blurhash encoding of images

Installation

npm i payload-blurhash-plugin

94

Stars

7

Forks

7

Open Issues

1 years ago

Last Updated

0

Weekly Downloads

v3.1.0

npm Version

94.4 KB

Unpacked Size

3

Dependencies

GitHub stars

Trends appear after 7 days of data. Daily snapshots have not started yet.

npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

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

Health Score

35/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/497083627-root.svg)](https://payloaddirectory.dev/plugins/497083627-root)
HTML
<a href="https://payloaddirectory.dev/plugins/497083627-root"><img src="https://payloaddirectory.dev/badge/497083627-root.svg" alt="Payload Directory"></a>
Updated Feb 14, 2025Created May 27, 2022Published Feb 14, 2025

README

payload-blurhash-plugin

Payload CMS plugin for automatic Blurhash encoding of images.

Getting started

  1. Install the package
  • Payload v2: npm i payload-blurhash-plugin@2
  • Payload v3: npm i payload-blurhash-plugin@3
  1. Add the plugin to your payload.config.ts:
import computeBlurhash from 'payload-blurhash-plugin';

export default buildConfig({
  /* ... */
  plugins: [computeBlurhash()],
});

Plugin options

Optionally, you can pass the following options to tweak the behavior of the plugin:

export type BlurhashPluginOptions = {
  /*
   * Array of collection slugs that the plugin should apply to.
   * By default, the plugin will apply to all collections with `upload` properties.
   */
  collections?: CollectionConfig['slug'][];

  /*
   * Pattern to determine which MIME types to target
   * Default: image/*
   */
  mimeTypePattern?: string;

  /*
   * Whether to show the Blurhash field when viewing media items in the admin interface.
   * Default: false
   */
  showBlurhashField?: boolean;
} & AlgorithmOptions;

The AlgorithmOptions depend on which algorithm you are using. Currently, there are two algorithms available: "blurhash" (the default) and "thumbhash". You can select an algorithm by specifying the algorithm name under the algorithm key.

These are the options for the "blurhash" algorithm:

type BlurhashOptions = {
  // Default: 32
  width?: number | undefined;
  // Default: 32
  height?: number | undefined;
  // Default: 3
  componentX?: number | undefined;
  // Default: 3
  componentY?: number | undefined;
};

There are currently no options for the "thumbhash" algorithm.

The defaults are chosen somewhat arbitrarily, they are just values that I've found to work nicely for me.

Similar plugins