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

directus-image-presets

v0.1.0

Published

Resolve Directus file IDs to optimized URLs across S3/CloudFront presets, with fallback to native Directus assets. Skip paying for Next.js Image optimization.

Readme

directus-image-presets

Resolve Directus file references (UUIDs, file objects, arrays, legacy formats) into optimized image URLs — served from S3/CloudFront when available, with automatic fallback to native Directus assets.

npm install directus-image-presets

Why

Directus ships server-side image presets, but the moment you put a CDN in front of S3-baked derivatives, every consumer has to:

  • detect whether a string is a UUID, a Directus URL, an S3 URL, or already-optimized
  • pick the right preset folder
  • fall back to Directus when the derivative doesn't exist yet
  • handle nested directus_files_id shapes
  • ditto for arrays of any of the above

This package does all of that, behind one resolver you configure once. Skip Next.js Image optimization fees by serving pre-baked WebP from your own CDN.

Quick start

import { createDirectusImageResolver } from "directus-image-presets";

export const images = createDirectusImageResolver({
  directusUrl: "https://cms.example.com",
  cdnUrl: "https://d2qyp4pqjcr206.cloudfront.net",
  s3Bucket: "my-app-images",
  presetFolders: {
    avatar: "avatar",   // 100x100
    card: "card",       // 400x400
    hero: "hero",       // 1200w
    og: "og",           // 1200x630
    webp70: "webp70",   // general purpose
  },
});

// Anywhere:
images.url(post.cover_image, "hero");
// → "https://d2qyp4pqjcr206.cloudfront.net/optimized/hero/<uuid>.webp"

images.url("9d657d01-9a28-4f11-a7c5-1cfb28384187", "card");
images.url({ directus_files_id: { id: "..." } }, "avatar");
images.url([null, file, "fallback-id"], "card"); // first non-null wins

Fallback to Directus

Sometimes the CDN derivative hasn't been generated yet. Use withFallback and switch on the client:

const { primary, fallback } = images.withFallback(post.cover, "hero");

<img src={primary} onError={(e) => { e.currentTarget.src = fallback; }} />

Or use the bundled React component:

import { DirectusImage } from "directus-image-presets/react";

<DirectusImage resolver={images} image={post.cover} preset="hero" alt="" />

Why the S3 layout?

Run a Lambda that subscribes to Directus file uploads, optimizes them with sharp, and writes:

s3://my-app-images/optimized/<preset>/<uuid>.<ext>

Point CloudFront at the bucket — it now serves your derivatives globally for ~$0.085/GB with zero compute on read.

API

createDirectusImageResolver(options): DirectusImageResolver
isDirectusFileId(value: string): boolean

resolver.url(image, preset?, fallback?): string
resolver.urlList(images, preset?, max?): string[]
resolver.withFallback(image, preset?): { primary, fallback, fileId }
resolver.isOptimizedUrl(url): boolean
resolver.directUrl(image, preset?, fallback?): string  // bypass CDN

Options

| Option | Default | Description | | --- | --- | --- | | directusUrl | — | Required. Public Directus URL | | cdnUrl | — | CloudFront/CDN URL. Omit → always serve from Directus | | s3Bucket | — | S3 bucket name; lets the resolver recognize raw S3 URLs in inputs | | s3Region | eu-central-1 | S3 region | | optimizedPrefix | optimized | Key prefix for derivatives | | derivativeExtension | webp | Output extension | | presetFolders | {} | Preset alias → folder name | | defaultFolder | preset name | Folder used when a preset isn't in presetFolders | | useCdn | true (if cdnUrl provided) | Set false for admin previews | | fallback | /images/placeholder.jpg | Returned when input is unrecognizable |

Input types the resolver accepts

  • UUID string ("9d657d01-...")
  • Directus URL ("https://cms.example.com/assets/<uuid>")
  • S3 URL ("https://my-bucket.s3.eu-central-1.amazonaws.com/...")
  • { directus_files_id: "uuid" }
  • { directus_files_id: { id: "uuid", ... } }
  • { id: "uuid" }
  • { filename_disk: "<uuid>.png" }
  • Arrays of any of the above (first non-null wins)
  • null / undefined → fallback

License

MIT