npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

payload-watermark-plugin

v0.3.0

Published

Conditional image watermarking for Payload CMS 3.x based on folder assignment

Readme

payload-watermark-plugin

Conditional image watermarking for Payload CMS 3.x based on folder assignment.

npm version license


Requirements

  • Payload CMS ^3.0.0
  • Node.js >=18.0.0
  • sharp >=0.31.0 — must be installed as a direct dependency in your consuming project
  • The Folders feature enabled in your Payload config (folders: true or a custom folders config)
  • Watermark images stored in a publicly accessible location (R2/S3 public bucket, CDN, etc.)

Installation

pnpm add payload-watermark-plugin sharp

sharp is listed as a peer dependency — you must install it explicitly in your project.


Configuration

1. Add the plugin to your payload.config.ts

import { watermarkPlugin } from 'payload-watermark-plugin'
import { buildConfig } from 'payload'

export default buildConfig({
  // ...
  plugins: [
    watermarkPlugin({
      collections: ['media'], // collections to enable watermarking for
    }),
  ],
})

2. Run the migration

After adding the plugin, create and apply the database migration for the watermark_settings global:

pnpm payload migrate:create
pnpm payload migrate

3. Regenerate types

pnpm generate:types
pnpm generate:importmap

Plugin Options

| Option | Type | Required | Description | |--------|------|----------|-------------| | collections | string[] | Yes | Slugs of collections to apply watermarking to. At least one required. The first entry is also used as the relationship target for the watermark image field. |


Admin Usage

After installation, a Watermark Settings global appears in the admin panel under the Settings group.

| Field | Description | |-------|-------------| | Enable Watermarking | Master switch. Turn off to disable all watermarking without changing other settings. | | Watermark Image | Select an image from your media library to use as the watermark. Must be a PNG for best results. Must be publicly accessible via URL. | | Enabled Folders | Select one or more folders. Only uploads assigned to these folders will be watermarked. | | Position | Where to place the watermark on the image (9 positions: top/center/bottom × left/center/right). Default: Bottom Right. | | Size (% of image width) | Watermark width as a percentage of the main image width. Range: 1–100. Default: 20. | | Opacity | Watermark transparency. Range: 0 (invisible) to 1 (fully opaque). Default: 0.8. |

Fields 2–6 are hidden when Enable Watermarking is unchecked.


How It Works

Hook timing

The plugin registers a beforeOperation hook on each configured collection. This hook fires before generateFileData, which means:

  • The watermark is applied to req.file.data (the raw image buffer)
  • All generated image sizes (thumbnails, etc.) will also carry the watermark
  • The original uploaded file gets the watermark baked in

Folder check

On each upload, the hook reads args.data.folder. If the assigned folder is in the enabledFolders list in the Global, watermarking proceeds. Otherwise the upload is passed through unchanged.

Watermark processing (sharp)

  1. Fetches the watermark image from its public URL
  2. Resizes it to the configured percentage of the main image width
  3. Applies opacity via a raw RGBA pixel loop (multiplies alpha channel by the opacity factor — preserves colour accuracy)
  4. Composites the watermark onto the main image using sharp's composite() with blend: 'over'

Error handling

  • If the watermark-settings global is not yet migrated (table missing), the hook logs a warning and passes the upload through unchanged
  • If watermark processing fails for any reason, the error is logged and the original upload proceeds — uploads are never blocked by watermark failures

Notes

  • Public watermark URL required: The watermark image must be reachable via HTTP from the server at upload time. If your storage bucket is private, either make the watermark image public or configure a pre-signed URL strategy separately.
  • PNG watermarks: Use PNG files with transparency for best results. JPEG watermarks will work but cannot have transparent backgrounds.
  • tempFilePath mode: If Payload is configured to stream uploads to temp files instead of memory (useTempFiles: true in express-fileupload), watermarking is skipped with a warning. The plugin requires req.file.data to be an in-memory Buffer.

License

CC-BY-SA-4.0 — Creative Commons Attribution-ShareAlike 4.0 International