s-kolbusz

payload plugin aspect preview

by s-kolbusz
Media & images
v3
^3.85.0
MIT

Overview

Summary generated from the README

Adds a live preview grid to configured upload collections so editors can adjust a crop or focal point and see the framing across several aspect ratios at once. It replaces the collection's upload UI and adds an aspectPreview UI field, with edits stored through Payload's upload workflow. Requires Payload and @payloadcms/ui 3.85 or newer and React 19. A standalone React editor component is also exported.

Features

  • Preview grid showing hero, card, thumbnail and mobile ratios side by side
  • Focal point and crop editing with previews that update as you edit
  • Configurable ratios with names, usage descriptions and six built-in defaults
  • Overlay bands marking areas covered by text or badges, validated at startup
  • Editor available before saving a new upload
  • Standalone React editor component usable outside Payload

Use cases

  • Check that a photo's subject stays visible in hero, card and mobile layouts before saving
  • Mark title and price areas so editors keep the subject clear of overlaid text
  • Embed the image framing editor in a demo or docs site without Payload

From the author

Payload CMS plugin for image cropping, focal point editing, and live responsive image previews across hero, card, and mobile aspect ratios.

Installation

npm i payload-plugin-aspect-preview

6

Stars

0

Forks

0

Open Issues

2 weeks ago

Last Updated

174

Weekly Downloads

v0.4.0

npm Version

112.1 KB

Unpacked Size

1

Dependencies

GitHub stars

60 since Sep 7

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

128+101 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 2026128
Dec 5, 2026142
Dec 4, 2026145
Dec 3, 2026131
Dec 2, 2026137
Dec 1, 2026127
Nov 30, 2026123
Nov 29, 2026158
Nov 28, 2026157
Nov 27, 2026330
Nov 26, 2026313
Nov 25, 2026316
Nov 24, 2026324
Nov 23, 2026338
Nov 22, 2026301
Nov 21, 2026279
Nov 20, 202699
Nov 19, 2026105
Nov 18, 202693
Nov 17, 202690
Nov 16, 202678
Nov 15, 202687
Nov 14, 202684
Nov 13, 202696
Nov 12, 2026135
Nov 11, 2026250
Nov 10, 2026254
Nov 9, 2026248
Nov 8, 2026237
Nov 7, 2026243
Nov 6, 2026227
Nov 5, 2026182
Nov 4, 202659
Nov 3, 202652
Nov 2, 202658
Nov 1, 202657
Oct 31, 202681
Oct 30, 202683
Oct 29, 202670
Oct 28, 202667
Oct 27, 202668
Oct 26, 202663
Oct 25, 202660
Oct 24, 202633
Oct 23, 202627
Oct 22, 202640
Oct 21, 202661
Oct 20, 202662
Oct 19, 202661
Oct 18, 2026106
Oct 17, 2026188
Oct 16, 2026199
Oct 15, 2026193
Oct 14, 2026181
Oct 13, 2026182
Oct 12, 2026184
Oct 11, 2026143
Oct 10, 202660
Oct 9, 202660
Oct 8, 202675
Oct 7, 2026238
Oct 6, 2026232
Oct 5, 2026232
Oct 4, 2026231
Oct 3, 2026222
Oct 2, 2026221
Oct 1, 2026203
Sep 30, 202643
Sep 29, 202642
Sep 28, 202640
Sep 27, 202643
Sep 26, 202650
Sep 25, 202643
Sep 24, 202647
Sep 23, 202659
Sep 22, 2026209
Sep 21, 2026209
Sep 20, 2026202
Sep 19, 2026192
Sep 18, 2026191
Sep 17, 2026188
Sep 16, 2026175
Sep 15, 202626
Sep 14, 202628
Sep 13, 202635
Sep 12, 202639
Sep 11, 202640
Sep 10, 202638
Sep 9, 202630
Sep 8, 202628
Sep 7, 202627

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

Health Score

78/100Excellent

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/1297786125-root.svg)](https://payloaddirectory.dev/plugins/1297786125-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1297786125-root"><img src="https://payloaddirectory.dev/badge/1297786125-root.svg" alt="Payload Directory"></a>
Updated Nov 21, 2026Created Jul 11, 2026Published Nov 18, 2026

README

Payload CMS Image Preview Plugin

npm version license

See how your photo fits before you save it.

One photo might need to work in a wide hero, a square card, and a portrait mobile layout. Image Preview for Payload CMS lets editors check those formats side by side, adjust the crop or focal point, and watch every preview update as they edit.

payload-plugin-aspect-preview is a Payload CMS plugin for image cropping, focal point editing, and responsive image previews. It adds a live aspect ratio preview grid to upload collections, so editors can check several image formats on one screen in the Payload admin.

Payload CMS image editor with crop and focal point controls beside live previews of the same photo in multiple aspect ratios

Install the plugin · Configure your website's image formats

Help editors choose images that fit

A photo can look great in the media library and lose its subject when it fills a different shape on the website. Editors need to see what stays in the frame while they choose the image's crop and focal point.

  • Check several formats at once. Compare hero, card, thumbnail, and mobile aspect ratios in a live preview grid.
  • Keep the subject in view. Move the focal point and see how the framing changes across the configured ratios.
  • Crop with the result in sight. Draw a crop while watching the previews on the same screen.
  • Preview new images before saving. The editor appears as soon as you select an image, including on a new upload.
  • See what your text will cover. Mark where a component puts a title, price, or badges over the photo, and editors keep the subject clear of it.
  • Use labels your editors recognize. Configure formats such as “Homepage hero” or “Product card” with descriptions of where they are used.

Developers add the plugin to their upload collections and configure the ratios used by their frontend. Editors get the previews directly in Payload. Six common ratios are included to get started: square, 4:3, 3:2, 16:9, portrait 9:16, and a 1200 × 630 social share format.

Installation

pnpm add payload-plugin-aspect-preview

Quick start

import { buildConfig } from 'payload'
import { aspectPreviewPlugin } from 'payload-plugin-aspect-preview'

export default buildConfig({
  // ...
  plugins: [
    aspectPreviewPlugin({ collections: ['media'] }),
  ],
})

Your media collection must have uploads enabled. To use Payload's image processing and persist focal points, configure sharp in your Payload config, keep focalPoint enabled, and define imageSizes or resizeOptions on the collection. See Payload's upload configuration.

For editors

  1. Select a new image or open an existing image in the configured upload collection.
  2. Move the focal point or draw a crop. Compare the live previews for your image formats.
  3. Save the document when you are happy with the framing. Payload applies the image edits through its upload workflow.

Preview your website's image formats

Give each preview the name of the component where the image will appear. Set its proportions to match your frontend:

aspectPreviewPlugin({
  collections: ['media'],
  aspectRatios: [
    { name: 'Homepage hero', ratio: '21:9', width: 21, height: 9, source: 'css', usage: 'Wide banner at the top of the homepage' },
    { name: 'Product card', ratio: '1:1', width: 1, height: 1, source: 'css', usage: 'Square images in the product grid' },
    { name: 'Mobile feature', ratio: '9:16', width: 9, height: 16, source: 'css', usage: 'Portrait image in the mobile layout' },
  ],
})

The previews simulate image framing using cover sizing and focal positioning. Configure the ratios yourself and use the saved focal point in your frontend's image positioning. The plugin previews the image inside each shape; it does not render your website's components or detect their styles automatically.

Show where your site puts text over the image

If a component lays a title, price, or badges over the photo, editors can't see what that text will cover. Add overlays to a ratio and its preview shows those areas as bands along the frame's edges:

aspectPreviewPlugin({
  collections: ['media'],
  aspectRatios: [
    {
      name: 'Product card',
      ratio: '4:3',
      width: 4,
      height: 3,
      usage: 'Title and price over the bottom of the photo',
      overlays: [
        { label: 'Badges', edge: 'top', min: 0.12 },
        { label: 'Title + price', edge: 'bottom', min: 0.22, max: 0.4 },
      ],
    },
    {
      name: 'Hero',
      ratio: '16:9',
      width: 16,
      height: 9,
      overlays: [{ label: 'Headline', edge: 'left', min: 0.35, max: 0.5 }],
    },
  ],
})

Preview grid with covered-area bands: chips along the top and title + price along the bottom of a 4:3 card, a headline down the left of a 16:9 hero, a caption along the bottom of a portrait

  • min is the share of the frame the component always covers. It is drawn as a solid band.
  • max is the share it covers at worst, such as a title that wraps to three lines. The stretch from min to max is hatched and ends in a dashed line. Leave max out when the area has a fixed size.
  • Both are fractions from 0 to 1 of the frame's height (top, bottom) or width (left, right). Measure them on your component at the size editors care about most.

The bands are fixed to the frame, so they stay in place while the image moves under them as you change the focal point or crop. They don't block the editor and follow Payload's light and dark themes. Ratios without overlays look exactly as before.

The plugin checks overlays when Payload loads its config. An invalid entry (an empty label, an unknown edge, a fraction outside 0–1, max below min, or an overlay that covers nothing) stops startup with an error that names the ratio and the overlay.

Configuration

OptionTypeRequiredDefaultDescription
collectionsstring[]yes—Upload collection slugs to enhance.
aspectRatiosAspectRatioConfig[]noDEFAULT_ASPECT_RATIOSRatios shown in the preview grid.
disabledbooleannofalseKeep the schema field but disable the upload override.

AspectRatioConfig

FieldTypeRequiredDescription
namestringyesDisplay label (e.g. "Social Share").
ratiostringyesDisplay token (e.g. "16:9").
widthnumberyesRatio numerator (or absolute px width).
heightnumberyesRatio denominator (or absolute px height).
source'css' | 'crop'noDisplay badge describing the intended use. Does not change image processing.
usagestringnoDescription shown in the card footer.
categorystringnoOptional metadata label. Does not group cards in the current UI.
overlaysAspectRatioOverlay[]noAreas your frontend covers with text or UI, drawn over the preview. See Show where your site puts text over the image.

AspectRatioOverlay

FieldTypeRequiredDescription
labelstringyesShown inside the band (e.g. "Title + price").
edge'top' | 'bottom' | 'left' | 'right'yesThe frame edge the covered area starts from.
minnumberyesFraction (0–1) of the frame always covered. Height for top/bottom, width for left/right.
maxnumbernoFraction (0–1, at least min) covered at worst. Defaults to min.

Examples

Multiple collections

aspectPreviewPlugin({ collections: ['media', 'avatars'] })

Disable without dropping the schema

aspectPreviewPlugin({ collections: ['media'], disabled: true })

Use the editor without Payload

The same editor ships as a plain React component under payload-plugin-aspect-preview/playground. Nothing reachable from that entry imports payload or @payloadcms/*, so it runs on any React 19 page: a demo, a docs site, a tool of your own. Payload and @payloadcms/ui are optional peer dependencies, so installing the package without them is fine.

pnpm add payload-plugin-aspect-preview

It is a client component. In the Next.js App Router, render it from a file that starts with 'use client':

'use client'

import { useState } from 'react'
import {
  AspectPreviewEditor,
  type AspectPreviewValue,
} from 'payload-plugin-aspect-preview/playground'

export function ImageDemo() {
  const [src, setSrc] = useState('/sample.jpg')
  const [value, setValue] = useState<AspectPreviewValue>({ focal: { x: 50, y: 50 } })

  return (
    <>
      {/* A picked file stays in the browser: it is shown through a blob: URL. */}
      <input
        type="file"
        accept="image/*"
        onChange={(e) => {
          const file = e.target.files?.[0]
          if (file) setSrc(URL.createObjectURL(file))
        }}
      />
      <AspectPreviewEditor src={src} value={value} onChange={setValue} />
    </>
  )
}

Revoke old blob: URLs with URL.revokeObjectURL once you replace them. The component imports its own stylesheets (the editor's and react-image-crop's), which the App Router accepts from any component.

PropTypeDefaultDescription
srcstring—The image: any URL the browser can load, blob: URLs included. Without it the editor shows emptyMessage.
aspectRatiosAspectRatioConfig[]DEFAULT_ASPECT_RATIOSRatios in the preview grid, overlays included.
valueAspectPreviewValue—Controlled value: { crop?, focal }.
defaultValueAspectPreviewValueno crop, focal at the centreStarting value when you leave out value.
onChange(value, { reason }) => void—The whole next value. reason is 'user', or 'normalize' when the editor only converted a legacy pixel crop to percent.
altstring'Edit'Alt text for the editable image.
className, style—Added to the root element (.focal-editor).
emptyMessageReactNode'Upload an image…'Shown while src is empty.

value.crop is a percent rectangle over the whole image, or undefined for no crop. value.focal is a 0–100 position inside the crop (inside the whole image when there is none), the same space Payload stores focalX and focalY in. To place something on the whole image, convert it with toFullImageFocal(value.focal, value.crop) (pass { x: 0, y: 0, width: 100, height: 100 } when there is no crop). The entry also exports AspectRatioPreviewGrid, DEFAULT_ASPECT_RATIOS, toCropRelativeFocal, isRealCrop and the types.

Theming. Outside the Payload admin the editor falls back to a light, neutral palette. Override any --apv-* variable on your own class to match your site:

.my-demo.focal-editor {
  --apv-bg: #0f1115;
  --apv-bg-subtle: #171a21;
  --apv-bg-muted: #1f232c;
  --apv-border: #2a2f3a;
  --apv-text: #e8eaee;
  --apv-text-muted: #9aa1ad;
  --apv-bg-inverse: #e8eaee;
  --apv-on-inverse: #0f1115;
}

The full list is at the top of src/styles.css. The root also has margin-top: 20px, which you can reset the same way.

How it works

The plugin replaces the configured collections' upload UI with CustomUpload and adds an aspectPreview UI field rendered by FocalPointEditor, a thin Payload wrapper around AspectPreviewEditor. Crop and focal point edits flow through Payload's upload-edits context. Payload applies the crop on save and persists focal coordinates as focalX and focalY.

The preview grid uses cover sizing equivalent to object-fit: cover and object-position based on the focal point. When a crop is active, the grid previews that crop region with the focal point measured relative to it.

Frequently asked questions

When should I use this plugin?

payload-plugin-aspect-preview adds live previews of multiple aspect ratios to Payload upload collections. Use it when one image needs to fit several formats, such as hero banners, product cards, thumbnails, and portrait mobile images. Configure aspectPreviewPlugin with your collection slugs and the ratios your frontend uses.

How does it differ from Payload's built-in crop and focal point tools?

Payload already supports image cropping, focal points, and generated image size previews. This plugin brings crop and focal point editing together with a preview grid that updates as you edit. Its preview ratios can represent your frontend's image containers, even when you do not generate separate files for those ratios.

Does it generate a separate crop for each preview?

No. The grid shows how one shared crop and focal point fit different aspect ratios. Adding a preview does not create a new image size. Configure generated image sizes through Payload's imageSizes option.

Is this a full page live preview?

It previews image framing inside the media editor. Use Payload's page live preview for the rest of your layout, text, and components.

Will the previews match my website?

They model cover sizing with focal positioning at your configured aspect ratios. Your frontend must use the corresponding ratios and saved focal coordinates. Different fit modes, additional crops, or image processing can change the result. Text your components place over the image is shown only where you describe it with overlays.

Requirements and compatibility

  • Payload and @payloadcms/ui ^3.85.0 (not needed for /playground)
  • React ^19.0.0
  • Node.js >=20.9.0

The replacement upload UI uses @payloadcms/ui internals (FileDetails, Dropzone, PreviewSizes, …). These are not a stable public API, so a Payload minor upgrade may require a plugin update. Pin your Payload version and test after upgrades.

License

MIT © Sebastian Kolbusz

Similar plugins