Images on a marketplace, a classifieds site, a community forum or a social app are not produced by a design team. They come from thousands of people, on every device ever made. One seller uploads a 48-megapixel HEIC-converted JPEG straight off a new phone. Another uploads a 300-pixel screenshot with a white border. A third uploads a landscape photo that the phone recorded as portrait and rotated with an EXIF tag. And most of them, without knowing it, upload the GPS coordinates of their home.
The platform's job is to make all of that look like one consistent, fast, safe catalogue. This article walks through how to do that with an image CDN in front of your upload storage: what to normalise, what to restrict, and what to protect.
The architecture: store originals, never resize on upload
A common first design resizes on upload: a worker generates a thumbnail, a medium and a large version and stores all of them. It works until the design changes. Then there is a migration job over millions of files, and for a few days half the catalogue is in the old sizes.
The alternative is to store only the original, in your own bucket, and let the edge make every rendition on demand. ZawCloud Images fetches; it does not store. Your upload flow writes the original to S3, R2, Google Cloud Storage or Azure, and the bucket can stay private. Edge nodes sign their own reads with a read-only key (see Serving images from a private bucket). Your database stores the object path. Templates build URLs from it:
https://a3f9c21b.zwcld.net/v1/listings/8f3a/2c91.jpg?w=480&h=360&fit=cover&q=auto
A redesign becomes a template change, and the next request for each listing gets the new look. Nothing has to be regenerated.
Normalise what people upload
Orientation
Phones often save the sensor's raw orientation and add an EXIF tag that says "rotate this 90 degrees". The edge applies that tag when it decodes the image, before anything else, so a sideways upload is delivered upright. Focal points and crop rectangles are written against the image as it is displayed, so they mean the same thing whatever the phone did.
Colour
Recent phones shoot in Display P3, a wider colour space than the sRGB that most browsers assume for an untagged image. When the colour profile is stripped without converting, colours come out dull and shifted, which is a bad look for a listing that is trying to sell something. The edge converts to sRGB first and then strips the profile, so the listing looks like the photo the seller took.
Borders and screenshots
trim=true cuts away a border of near-uniform colour before resizing. Screenshots
with white margins, scanned documents and product shots on a white sheet then fill their
tile instead of shrinking into the middle of it. An image that is a single colour is left
alone.
Consistent tiles from any shape
A search results grid needs every tile the same size, but uploads come in every aspect ratio. Two approaches work, and they suit different catalogues:
-
Fill and crop (
fit=cover), ideally withai_crop=trueso the crop follows the subject rather than the centre. Best for photographs of things: cars, flats, clothes. -
Fit and pad (
fit=pad&bg=f4f4f5), which shows the whole image on a neutral tile. Best when cropping could hide something a buyer needs to see, such as a scratch on the corner of a table.
Strip what people did not mean to share
A photo taken at home and uploaded to a classifieds site can carry the exact GPS coordinates of that home, the phone's model and serial number, and the time it was taken. Republishing that is a privacy problem for your users and, in many jurisdictions, a compliance problem for you.
The edge strips metadata by default. Every delivered rendition has its EXIF,
XMP and other metadata removed unless the URL explicitly says strip=false. So
every image your platform serves is clean, including ones uploaded before anybody thought
about it. We wrote about what typically hides in a photo's metadata in
The metadata you did not mean to
publish.
The original in your bucket still has its metadata. Whether to keep it there is a separate decision for your retention policy, and the CDN does not depend on it either way.
Restrict what can be requested
User-generated content means a lot of images, and public URLs mean anyone can edit the query string. Left open, a scraper or a curious visitor can ask for every width from 1 to 5000 of every image you host. Each of those is an origin read, a decode, an encode and a cache entry, and all of it counts against your plan.
The console's Limits tab has two rules for this, and a platform should usually turn on one:
-
Presets only. A URL may name a preset and nothing else.
?preset=cardis served, while?w=800and?preset=card&w=800are refused with400 preset_required. This is the tightest setting. A preset holds a size, fit, format, quality and watermark, so it suits platforms where that is all each image slot needs. -
Permitted output sizes. A list of widths and heights. Every other
parameter is still allowed, but sizes only with listed values. Choose this when your
templates also use
trim,fit=padwithbg,ai_croporq=auto, which presets cannot carry and presets-only would refuse.
Both refuse rather than adjust. A size that is not on the list gets a 400, not
the nearest allowed size, so the URL always means exactly what it says. And both are checked
before the origin is contacted, so a refused request costs neither a bucket read nor an
encode.
Defaults on every node also stop the worst uploads from becoming an outage: originals over 25 MB and images over 50 megapixels (checked on the decoded image, so a small file that decompresses into a huge one is caught too) are refused, and no output edge exceeds 5,000 pixels.
When a listing changes or disappears
Sellers replace photos, and moderators remove listings. Two things make that work:
- Use a new object path for a new photo wherever you can (for example, a random id per upload, as in the URL above). A new path is a new cache entry, so there is nothing to invalidate, and the old URL can expire naturally.
-
Purge when you must remove something now. A moderation action should
delete the original and call the management API with a token that has only the
purgescope. A purge by path removes every size and format of that image at once, so your moderation tool does not need to know which renditions were ever served.
POST /api/v1/purges
{ "target": "/v1/listings/8f3a/2c91.jpg" }
A purge also clears the node's short-lived memory of a missing file. The edge remembers an
origin 404 for about 30 seconds so that a broken image on a busy page does not
hit your bucket on every view, and a purge makes it look again immediately.
Placeholders for infinite scroll
Feeds and search results scroll quickly, and a grid of grey boxes feels slow even when it
is not. When a photo is uploaded, call the delivery URL once from your backend with
?thumbhash=true and store the result next to the path. It is a few dozen bytes
that the app or page renders instantly as a blurred preview with the right colours and aspect
ratio. Store the width and height too, and your layout never jumps.
?info=true returns dimensions, dominant colours, a BlurHash and a ThumbHash in
one call.
Abuse and hotlinking
Popular platforms get their images embedded on other sites and scraped by bots. The Bot & Hotlink Shield refuses requests from sites you have not allowed, known scrapers and, if you choose, AI crawlers. It lets search engines and link previews through, so listings still show up in image search and in chat apps. It also leaves native mobile apps alone, because their HTTP clients send no referrer.
To be told when something is going wrong, register a webhook for
request.failed, which fires when a node refuses a request it can attribute to
your account, with the reason. A sudden spike in dimension_not_permitted or
hotlink_blocked is usually someone trying something. quota.warning
tells you at 90% of your monthly allowance, before a viral listing becomes a surprise.
A starting configuration
- Originals in a private bucket, one random path per upload.
- A short, fixed list of tile and detail sizes, written into your templates with
trim, the fit mode that suits your catalogue, andq=auto. - Permitted output sizes set to exactly that list. If your slots need nothing but size, fit and quality, use presets with presets-only mode instead.
- Metadata stripping left at its default.
- ThumbHash, width and height stored at upload.
- Shield on, with your own domains and apps allowed.
- Moderation tooling with a purge-only management token.