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-img-convert

v1.0.1

Published

Payload CMS plugin that automatically converts and resizes uploaded images to WebP, AVIF, or other formats using Sharp

Readme

payload-img-convert

Automatic image conversion and resizing for Payload CMS v3.

npm version npm downloads license


Official Homepage | GitHub Repository


Why?

Payload 3 doesn't include built-in format conversion. Most sites need WebP or AVIF for performance, but manually converting every upload is tedious. This plugin handles it automatically — convert on upload, resize to fit constraints, and let editors pick the format from the admin UI.

Features

  • Automatic format conversion — WebP, AVIF, PNG, JPEG
  • Aspect-ratio preserving resize — constrain by max width/height without distortion
  • Max file size gate — skip conversion for oversized files
  • Per-format quality options — fine-tune Sharp settings per format
  • Admin UI format selector — dropdown in the upload sidebar
  • Re-conversion support — change format on existing uploads
  • Graceful fallback — if conversion fails, the original file is kept
  • Zero config defaults — works out of the box with sensible defaults

Quick Start

npm install payload-img-convert
// payload.config.ts
import { imageConverterPlugin } from 'payload-img-convert'

export default buildConfig({
  plugins: [
    imageConverterPlugin({
      collections: ['media'],
    }),
  ],
})

That's it. All images uploaded to the media collection will be converted to WebP at quality 80.

Configuration

| Option | Type | Default | Description | | --------------------- | ---------------- | ----------- | ------------------------------------------------------------ | | collections | string[] | required | Upload collection slugs to target | | defaultFormat | ImageFormat | 'webp' | Default output format | | quality | number | 80 | Default quality (0–100) | | formatOptions | FormatOptions | undefined | Per-format Sharp options (see below) | | enableFormatSelector| boolean | true | Show format dropdown in admin sidebar | | formats | ImageFormat[] | All four | Formats available in the dropdown | | disabled | boolean | false | Kill switch — disables conversion, keeps field for schema | | maxWidth | number | undefined | Max width in px (aspect ratio preserved, no upscaling) | | maxHeight | number | undefined | Max height in px (aspect ratio preserved, no upscaling) | | maxFileSize | number | undefined | Max file size in bytes — files exceeding this skip conversion|

Full example

imageConverterPlugin({
  collections: ['media', 'avatars'],
  defaultFormat: 'avif',
  quality: 75,
  maxWidth: 2560,
  maxHeight: 1440,
  maxFileSize: 10 * 1024 * 1024, // 10 MB
  formats: ['webp', 'avif', 'jpeg'],
  formatOptions: {
    webp: { quality: 85, effort: 4 },
    avif: { quality: 65, effort: 6 },
    jpeg: { quality: 80, progressive: true, mozjpeg: true },
  },
})

Format options

Each format accepts the corresponding Sharp output options:

| Format | Notable options | | ------ | -------------------------------------------- | | WebP | quality, lossless, nearLossless, effort | | AVIF | quality, lossless, effort | | PNG | compressionLevel, palette, quality, effort | | JPEG | quality, progressive, mozjpeg |

How It Works

The plugin registers a beforeOperation hook on each targeted collection. When an image is uploaded (or re-converted), the hook:

  1. Reads the target format from the admin UI selector (or falls back to defaultFormat)
  2. Checks file size against maxFileSize (skips if exceeded)
  3. Resizes the image if maxWidth or maxHeight are set (aspect ratio preserved, no upscaling)
  4. Converts to the target format using Sharp with the configured quality/options
  5. Replaces the file data, MIME type, and extension on req.file

SVGs and GIFs are always skipped. If conversion fails, the original file is kept unchanged.

Supported Formats

| Format | Extension | MIME Type | Notes | | ------ | --------- | ------------ | ---------------------------------------- | | WebP | .webp | image/webp | Best all-round choice, wide support | | AVIF | .avif | image/avif | Smaller files, slower encoding | | PNG | .png | image/png | Lossless, good for graphics | | JPEG | .jpg | image/jpeg | Universal compatibility, lossy |

Contributing

See CONTRIBUTING.md.

License

MIT — Stian Larsen