Image Providers
An image provider makes resized copies of each image, called variants, and fills srcset. You set it in media.images:
import { defineCms } from "tenoncms";
import { ipx } from "tenoncms/media/ipx";
import { local } from "tenoncms/media/local";
export default defineCms({
// ...
media: {
storage: local({ dir: ".uploads" }),
images: { provider: ipx() },
},
});
Each provider is its own import, tenoncms/media/<name>, so a site loads only the one it uses. npm create tenoncms asks for one and writes its config.
Do you need one?
Without a provider, images are served as uploaded. A read returns the original as src and an empty srcset. That is enough when:
- the images are small, or
- your framework resizes them, like Astro's
<Image>or Nuxt Image. See Use your framework's image component.
The admin still shows small previews. On upload, the browser draws each image at 320 px on the short side and stores the copy. This needs no package and no work on the server.
Use a provider when you want responsive images without another tool, for example because editors upload large photos.
| Your site runs on | Use |
|---|---|
| A Node server | ipx() |
| Cloudflare Workers | cloudflare({ binding: env.IMAGES }) |
| Vercel | vercel() |
| Netlify | netlify() |
| Any host behind Cloudflare with image transformations | cloudflare() |
| Any host, with an image service you already use | imgix(), cloudinary(), imagekit(), bunny() |
| Any host, with your own image server | imgproxy(), thumbor() |
Providers
There are two kinds of provider:
- A rendering provider makes the variants itself. Tenon serves them at
/_tenon/media/img/<modifiers>/<key>and stores them in your media storage, under.variants/<key>/. It renders a variant on its first request, or right after the upload withprerender: true. It serves only the variants your config can produce, so nobody can ask for other sizes. - A URL provider builds URLs for an image service. Tenon renders and stores nothing. The service MUST be able to load the original.
| Provider | Import | Kind | Runs on | Ignores |
|---|---|---|---|---|
ipx() | tenoncms/media/ipx | Rendering, with sharp | Node, Bun, Vercel functions | Nothing |
cloudflare() | tenoncms/media/cloudflare | Rendering with binding, else URL | Workers with binding, else any site on a Cloudflare zone | Nothing |
vercel() | tenoncms/media/vercel | URL | Vercel | height, fit, format, background, blur |
netlify() | tenoncms/media/netlify | URL | Netlify and netlify dev | background, blur |
imgix() | tenoncms/media/imgix | URL | Anywhere | Nothing |
cloudinary() | tenoncms/media/cloudinary | URL | Anywhere | Nothing |
imagekit() | tenoncms/media/imagekit | URL | Anywhere | Nothing |
bunny() | tenoncms/media/bunny | URL | Anywhere | fit, format, background |
imgproxy() | tenoncms/media/imgproxy | URL, self-hosted | Anywhere | Nothing |
thumbor() | tenoncms/media/thumbor | URL, self-hosted | Anywhere | Nothing |
"Ignores" lists the image options a provider cannot apply.
ipx() renders variants with IPX, which uses sharp. Tenon does not install it, because sharp is a large native package:
npm install ipx@4.0.0-beta.1
pnpm add ipx@4.0.0-beta.1
yarn add ipx@4.0.0-beta.1
bun add ipx@4.0.0-beta.1
import { ipx } from "tenoncms/media/ipx";
images: { provider: ipx({ prerender: true }) },
false.- sharp is native code. Install the packages on a machine with the same OS and CPU as the server, or in the same container image.
tenoncms/media/ipxthrows on Cloudflare Workers.
cloudflare() has two modes.
With an Images binding, on Workers, Tenon renders the variants through Cloudflare Images and stores them. wrangler dev renders locally:
import { env } from "cloudflare:workers";
import { cloudflare } from "tenoncms/media/cloudflare";
images: { provider: cloudflare({ binding: env.IMAGES }) },
{
"images": { "binding": "IMAGES" },
}
Without a binding, variant URLs point to /cdn-cgi/image/… on the zone that serves the site. Tenon renders nothing. The site MUST be proxied by Cloudflare, with image transformations on for the zone. This also works for a site on Node or Vercel.
images: { provider: cloudflare() },
env.IMAGES with env from cloudflare:workers. Default: URLs on /cdn-cgi/image/.binding. Default: false.vercel() uses Vercel Image Optimization. Outside Vercel, as in development, it returns the originals, so development needs no setup:
import { vercel } from "tenoncms/media/vercel";
images: { provider: vercel() },
On Vercel, Image Optimization MUST be on, with the same widths as images.sizes. Set them in the framework config:
// astro.config.ts
import vercel from "@astrojs/vercel";
export default defineConfig({
adapter: vercel({ imagesConfig: { sizes: [320, 640, 1024, 1536, 1920], domains: [] } }),
});
// nuxt.config.ts
export default defineNuxtConfig({
nitro: { vercel: { config: { images: { sizes: [320, 640, 1024, 1536, 1920], domains: [] } } } },
});
// vite.config.ts. Standalone uses the same `nitro()` option.
const vercel = { config: { images: { sizes: [320, 640, 1024, 1536, 1920], domains: [] } } };
export default defineConfig({
plugins: [tanstackStart(), nitro({ vercel }), viteReact(), tenonAdmin()],
});
- A width between two allowed widths rounds up to the next one.
- Vercel picks the format from the browser. Only
widthandqualityapply. - Files in a bucket: set
publicUrlon the storage, and allow its host inremotePatternsof the sameimagesblock. - The Vercel starters of
npm create tenoncmswrite this config with the default widths. Change both lists together.
sizes of the Vercel image config. Default: [320, 640, 1024, 1536, 1920].netlify() uses the Netlify Image CDN. It works on Netlify and in netlify dev:
import { netlify } from "tenoncms/media/netlify";
images: { provider: netlify() },
A file on another origin, like a public bucket, MUST be listed in remote_images of netlify.toml.
/.netlify/images.import { imgix } from "tenoncms/media/imgix";
images: { provider: imgix({ baseURL: process.env.IMGIX_BASE_URL! }) },
URLs are <baseURL>/<key>?w=…. Point the imgix source at the bucket, or at https://<site>/_tenon/media/files/ for files on the local disk.
https://my-site.imgix.net.import { cloudinary } from "tenoncms/media/cloudinary";
images: { provider: cloudinary({ baseURL: process.env.CLOUDINARY_BASE_URL! }) },
baseURL decides where Cloudinary finds the file:
baseURL | Cloudinary loads |
|---|---|
https://res.cloudinary.com/<cloud>/image/upload/<folder> | The file through an auto-upload mapping of <folder> to the bucket or to https://<site>/_tenon/media/files/ |
https://res.cloudinary.com/<cloud>/image/upload | A file you uploaded to Cloudinary yourself. The key without its extension is the public ID |
https://res.cloudinary.com/<cloud>/image/fetch | The file URL. Set origin, so URLs of local files are absolute |
…/image/fetch, like https://example.com.import { imagekit } from "tenoncms/media/imagekit";
images: { provider: imagekit({ baseURL: process.env.IMAGEKIT_BASE_URL! }) },
URLs are <baseURL>/<key>?tr=…. Point the ImageKit origin at the bucket, or at https://<site>/_tenon/media/files/.
https://ik.imagekit.io/<id>.import { bunny } from "tenoncms/media/bunny";
images: { provider: bunny({ baseURL: process.env.BUNNY_BASE_URL! }) },
URLs are <baseURL>/<key>?width=…. Point the pull zone at the bucket, or at https://<site>/_tenon/media/files/. Bunny picks the format.
https://my-site.b-cdn.net.import { imgproxy } from "tenoncms/media/imgproxy";
images: {
provider: imgproxy({
baseURL: process.env.IMGPROXY_URL!,
key: process.env.IMGPROXY_KEY,
salt: process.env.IMGPROXY_SALT,
}),
},
imgproxy loads the file URL. URLs of local files are relative, so set IMGPROXY_BASE_URL on the imgproxy server to your site, or pass origin.
https://img.example.com.key and salt, URLs are signed. Without them, URLs are unsafe, which the server MUST allow.https://example.com. Not needed with IMGPROXY_BASE_URL.import { thumbor } from "tenoncms/media/thumbor";
images: {
provider: thumbor({
baseURL: process.env.THUMBOR_URL!,
key: process.env.THUMBOR_KEY,
origin: "https://example.com",
}),
},
Thumbor loads the file URL through its HTTP loader.
https://thumbor.example.com.unsafe, which the server MUST allow.https://example.com.With a prefix on the storage, a URL provider still builds <baseURL>/<key>. Point the service at the prefix folder of the bucket.
Sizes and presets
media.images sets how Tenon builds src and srcset for every image:
import { defineCms } from "tenoncms";
import { ipx } from "tenoncms/media/ipx";
import { local } from "tenoncms/media/local";
export default defineCms({
// ...
media: {
storage: local({ dir: ".uploads" }),
images: {
provider: ipx(),
sizes: [320, 640, 1024, 1536, 1920],
format: "webp",
quality: 85,
presets: {
avatar: { width: 128, height: 128, fit: "cover" },
},
},
},
});
sizesare the widths insrcset. Widths above the original are left out. Default:[320, 640, 1024, 1536, 1920].formatandqualityapply to every variant. Default:"webp"and85.presetsare named sets of options:width,height,fit,format,quality,backgroundandblur. A field uses one withimage: { preset: "avatar" }. A field that names a missing preset stops the server at startup.maxSizeis the largest image that gets variants. Default: 50 MB.
SVG files and images above maxSize get the original as src and an empty srcset.
A field can override these options. See Image sizes. Every option is in the configuration reference.
After a change
Stored variants do not follow a change to sizes, presets, format, quality or the provider. Run tenon media regenerate:
npx tenon media regenerate
- It deletes the stored variants that your options no longer produce.
- With
prerender, it renders the missing ones.--forcerenders all of them again, for example after a sharp upgrade. - A config that runs only on Cloudflare cannot run in the CLI. Call
cms.media.regenerate()there, from a route or a job. - A URL provider stores nothing. Its new URLs take effect on the next read.
Write your own provider
A provider is an object with getImage(). This one builds URLs for an image service:
import type { ImageProvider } from "tenoncms";
export const myImages = (baseURL: string): ImageProvider => ({
getImage({ key, width }, modifiers) {
const params = new URLSearchParams({ w: String(modifiers.width ?? width) });
if (modifiers.quality) params.set("q", String(modifiers.quality));
return { url: `${baseURL}/${encodeURI(key)}?${params}` };
},
});
src holds the storage key, the url of the original, width and height. It runs on the server, on every read.storage. With it, Tenon serves and stores the variants, like ipx().render.The URL providers port the mappings of Nuxt Image. Another Nuxt Image provider translates the same way.
Related resources
- Media: the media library and responsive images.
- Image: image fields, their options and what a read returns.
- Media storage: where the originals and the variants live.
- tenon media: render the variants again.