Zack Design’s Nexxara is an event media platform for production companies and event photographers: photographers upload, event managers curate, and attendees open the gallery from a QR code. Its central idea is to never bake a watermark into a file. Photos sit untouched in Cloudflare R2 (Cloudflare’s file storage, equivalent to Amazon S3), and a Cloudflare Worker, a small program running in Cloudflare’s data centres at files.nexxara.media, lays up to three overlays onto each photo as it is requested, using the draw option of Cloudflare’s Image Resizing service. It is in closed beta.
This post covers:
- why it exists, what it does, and how Postgres decides which rows each user can see;
- how the image Worker sizes and places watermarks as each photo is requested;
- captioning photos with a vision model, grouping them by capture time, a Durable Object that streams upload progress to the admin screen, and reading video keyframes before playback;
- two Image Resizing behaviours that are not in the documentation: it fetches from the Worker that called it, and it refuses images over 100 megapixels;
- the Stripe library default that hangs a Worker.
Why it exists
One run of a festival produces thousands of photos from several photographers. Each photographer wants their own mark on their work, and the event operator wants the sponsor’s mark on all of it. Today that means re-exporting every JPEG whenever a logo changes, then sharing a Dropbox link that expires.
What it does
Production companies run events. Events have editions: the same festival in November and again in March. Each edition has photographers and videographers uploading, an event manager curating, and attendees who want the photos afterwards.
- Photographers upload straight to R2 using pre-signed upload links (
getSignedUrlinsrc/lib/services/storage-service.ts), so the file bytes never pass through the app. - Event managers curate: keep or drop, organise into collections, reorder by drag and drop (
@dnd-kit), set watermark positions. - Attendees open the gallery from a QR code or a link (the
qrcodelibrary renders it in the edition’s share dialog). They sign in with an emailed one-time link viasupabase.auth.signInWithOtp, so there is no password. - Galleries use
react-photo-albumto lay photos out in rows of equal height, with video alongside photos.
Roles are a Postgres enumerated type, user_role: basic, media, event_manager, admin and super_admin. Every table has row-level security enabled. That means Postgres itself filters which rows a user can see, rather than the application code. The migrations in supabase/migrations/ write those policies against auth.uid() and the caller’s row in user_profiles, and database tests check them. The background queue consumer runs with the service-role key, which bypasses the policies, and is kept as a separate code path for that reason.
Watermarks are drawn when the photo is requested
The gallery never links to a file in R2. It links to the image Worker, with the transformation described in the query string:
https://files.nexxara.media/photos/editions/{id}/{filename}.jpg?width=400&fit=cover&quality=80&editionWatermark=watermarks/{id}/{filename}
The Worker (workers-nexxara/image/index.ts) reads the width, height, quality, fit, format and gravity parameters. Then it builds cf.image.draw, a list of overlays to draw on top. Three sources feed it: the platform’s own mark, the edition’s mark, and the photographer’s.
Each overlay is itself a URL back to the same Worker. It is requested at twice its target width, as a PNG at full quality with sharpening on (format=png, quality=100, sharpen=3, fit=scale-down). So Image Resizing shrinks a sharp source instead of enlarging a soft one.
Sizing is the hard part. Overlays are specified in output pixels, so calculateWatermarkWidth() in watermark-positioning.ts picks a share of the output width based on the photo’s shape:
| Photo shape (width to height) | Overlay width as a share of photo width |
|---|---|
| Wider than 3 to 1 | 4% |
| Wider than 2 to 1 | 5% |
| Wider than 1.5 to 1 | 6% |
| Other landscape, and square | 8% |
| Portrait | 10% |
The result is clamped to at least 80 pixels, at most a quarter of the photo’s width, and never more than twice the overlay’s own source width. When two marks share a corner, the second sits beside the first: 15 pixels past the first mark’s rendered width, with 20 pixels of padding from the photo’s edge. Stepping by a fixed estimate of 70 pixels is not enough: wide marks overlap. The estimate is only the fallback when no width is available.
One trap in this layer: Image Resizing centres an overlay when none of top, bottom, left or right is set. A center case that sets bottom and right, as a general default would, renders a “centred” watermark in the bottom-right corner. So the center case is empty, case "center": break;, with a comment explaining why.
Unit tests cover the Worker’s configuration and positioning modules.
Captions from a vision model, moments from the clock
Each upload puts one message per file on the photo-processing-queue. The consumer takes up to ten messages at a time and waits at most 30 seconds to fill a batch. It retries a failed message three times, then parks it on a separate dead-letter queue (photo-processing-dlq) for inspection.
It extracts EXIF, the metadata a camera writes into each file, with exifr. Then it runs a vision pass on Workers AI, Cloudflare’s hosted models. One vision model does the work, with no image-classification model such as ResNet-50 alongside it. @cf/llava-hf/llava-1.5-7b-hf captions a downsized copy of each photo. Sending the original returns Workers AI error 3006, “Request too large”. @cf/meta/llama-4-scout-17b-16e-instruct handles the text tasks.
Writes are guarded by ai_analyzed_at, so a message delivered twice cannot overwrite a photo that has already been analysed. force: true on the message bypasses the guard for a deliberate re-run. Password-protected galleries skip the vision pass entirely.
Grouping photos into moments, the sections a gallery is organised by, uses no model at all. A per-day language-model call, a fixed 30-minute splitter and an image classifier all look plausible, but they disagree with each other and drop photos they can’t place. src/lib/bracketing/moments.ts does it in one deterministic pass over capture times:
- Always split at a gap of three hours or more (overnight) and at a break of an hour or more.
- Then split at the largest remaining gaps until moments average about 20 items. Only gaps that stand out from the shoot’s own rhythm count: at least five times the median gap and at least ten minutes. A burst-heavy wedding and a slow hike both split at their real pauses.
- Fold moments of one to three items into the neighbour across the smaller gap, but never across a night.
- Split a moment that is still too big at its own largest pause.
Every photo and video ends up in exactly one moment. Moments are named by the part of the day in the gallery’s time zone. One optional model call can name them from what the photos show, never for protected galleries.
The trap in this pipeline is time zones. The EXIF DateTimeOriginal field is a wall-clock time with no zone attached. OffsetTimeOriginal, when present, says which zone that wall clock belongs to, and turning the pair into a universal instant means subtracting the offset. Adding it instead is an easy slip: it puts every photo from a shoot ten hours ahead of UTC ten hours into the future, and feeds nonsense into the grouping.
Capture times are stored as true UTC instants. The zone comes from the photo’s own offset tag, then the edition’s time zone, then the photographer’s default, then UTC. recompute_exif_date_taken(edition_id) re-derives them from the stored EXIF data when either setting changes.
A live progress bar for uploads
An admin watching a large upload wants a progress bar, not a refresh button. ProgressActor is a Durable Object: a single instance of a small program that Cloudflare runs in exactly one place, with its own storage, so several users can share live state through it. There is one per edition (idFromName("edition:{uuid}")), and a malformed id gets a 404 rather than falling through to a shared default instance.
The queue consumer and the upload routes POST typed events to it: upload:progress, ai:complete, bracket:started and nine others. A small function in state-manager.ts folds each event into the current state. The state is saved to the object’s storage and broadcast over WebSocket to every admin browser tab connected to it.
It uses the WebSocket hibernation API, calling this.ctx.acceptWebSocket(server) so the runtime owns the connections. Keeping them in an in-memory Set, the obvious approach with the @cloudflare/actors beta, doesn’t work: the set does not survive the object being put to sleep between messages, so a broadcast after waking goes to nobody.
A second trap in the same object: a JavaScript Map for the upload state. Both storage.put() and the JSON.stringify used for broadcasting turn a Map into an empty {}, so every saved state and every message would carry zero uploads. The state is a plain object, and a test round-trips an upload through JSON to prove it.
The WebSocket path is intercepted in worker/index.ts before OpenNext (the adapter that runs Next.js on Workers) sees the request, because a WebSocket connection cannot pass through the Next.js router. Only WebSocket upgrades and GET requests are accepted there. The code that produces events talks to the Durable Object directly, so nobody outside the Worker can forge progress for an edition.
Video: reading the keyframes before playback
Videos are inspected with mp4box, a library that reads the structure of MP4 files, before they are shown. The keyframes route parses the file’s index (the moov atom) and collects the timestamps of the frames that can be decoded on their own. Those drive the scrubbing slider in the video editor, and Cloudflare Media Transformations (/cdn-cgi/media/) produce the preview frames.
Video bytes are served by the Worker entrypoint rather than a Next.js route. Next.js and OpenNext strip the Content-Length header from streamed responses, and a download cut off halfway then looks identical to a complete one.
Two things Image Resizing does that the docs do not say
It calls you back. Transforming an image from a Worker means calling fetch(imageUrl, { cf: { image } }). Image Resizing then fetches the source image from that URL, which is the same Worker. Without a guard, that is an endless loop of transform requests. Image Resizing adds image-resizing to the via header of its own fetch. The Worker checks for it, and when it is present serves the untouched bytes from R2 with no transform.
It has a size ceiling, and every version of the photo fails. Image Resizing rejects inputs over 100 megapixels with ERROR 9413: Could not resize the image: The image is too large. A stitched panorama of 23,957 by 4,416 pixels is 105.8 megapixels. Every request goes through a transform, so without a fallback every version of that photo comes back as a 403 Forbidden, even the plain URL with no parameters, and the gallery draws a broken-image placeholder.
The Worker recognises that specific error message and serves the original file untransformed. It adds an X-Nexxara-Transform: bypassed-oversized response header, so the fallback is visible in the browser’s developer tools. One request is deliberately excluded: format=json, which asks Image Resizing for the image’s dimensions rather than its pixels. The queue worker recovers an oversized photo’s dimensions from that very error message. Returning image bytes there would leave oversized panoramas with no dimensions at all.
Full-resolution downloads have a related problem. Overlays are sized in output pixels, and with no width in the request the Worker does not know the output size, so watermarks come out tiny on big files. The app passes the stored dimensions as iw and ih. Failing that, the Worker asks Image Resizing for them with format=json. The gallery always sends a width, so it never has to ask.
On the Next.js side, imageLoader.ts rounds the width that next/image computes up to the next multiple of 500 pixels: a 750-pixel request becomes 1,000, and 1,200 becomes 1,500. So the edge cache sees a handful of sizes per photo instead of one per screen size. The loader must not overwrite a width the gallery has already chosen: doing so serves a thumbnail about 280 pixels wide as an image about 1,000 pixels wide.
The Stripe default that hangs a Worker
Downloads are free and watermarked, with an optional tip, and tips are charged in the photographer’s own currency. Tips and subscriptions go through Stripe, the payments provider.
new Stripe(key) uses the library’s Node.js HTTP client, and in the Workers runtime that client never returns. checkout.sessions.create hangs, and the POST that starts a tip checkout stays pending forever. Every Stripe construction passes httpClient: Stripe.createFetchHttpClient(). Webhook signature checks use constructEventAsync with Stripe.createSubtleCryptoProvider(), because the synchronous Node.js crypto path is not available on Workers either. The library documents both helpers; it does not fail loudly when you leave them out.
The stack, in one place
Next.js 16 on Cloudflare Workers via OpenNext, as a single Worker with a custom entrypoint (worker/index.ts). The entrypoint adds the queue consumer, the Durable Object, the video stream and three scheduled jobs: subscription expiry every hour, storage recalculation daily at 02:00 UTC, and R2 orphan cleanup daily at 03:30 UTC.
Supabase for Postgres, sign-in and row-level security. Cloudflare R2 for media and for OpenNext’s page cache. Workers AI for vision and text. Stripe for tips and subscriptions, react-photo-album for the gallery layout, mp4box for reading video files.
The image Worker is deployed separately from workers-nexxara/image, with placement.mode = "smart", which lets Cloudflare run it near the services it calls rather than near the user.
Beta
Nexxara is in closed beta with production companies and event photographers. If you run events, shoot events, or coordinate photographers across multiple editions, request access on the site. We would genuinely love to hear what you need from it.
