Prompt
I'm building a landing page builder and need on-the-fly image resizing
Latest observation
Oct 23, 2026
OpenAI APIWeb search: off
A good way to do on-the-fly image resizing for a landing page builder is to put an image transformation service in front of your storage, then generate responsive variants at request time or on first request and cache them.
Recommended architecture
1) Store originals
Keep the original upload in object storage:
- S3
- R2
- GCS
- Azure Blob
2) Serve through an image CDN / resizing layer
Use one of these:
- Cloudinary
- Imgix
- ImageKit
- Fastly Image Optimizer
- Cloudflare Image Resizing
- Self-hosted: Sharp behind an API/CDN
3) Request images with params
Typical URL pattern:
https://img.example.com/my-image.jpg?w=800&h=450&fit=cover&q=80&fm=webp
Common options:
wwidthhheightfit=cover|contain|fill|insideqqualityfm=webp|avif|jpg|pngdpr=2for retinacrop=faces|entropy|center
4) Cache aggressively
Cache transformed images at the edge and in the browser:
- immutable cache headers for versioned URLs
- long TTL
- purge on replacement of source images
Best implementation pattern for a builder
If users drag/drop images into sections, you usually want:
- original upload
- responsive breakpoints generated or on-demand
- srcset output for different screen sizes
- automatic format negotiation to WebP/AVIF
Example HTML:
<img
src="https://img.example.com/photo.jpg?w=800&fm=webp"
srcset="
https://img.example.com/photo.jpg?w=400&fm=webp 400w,
https://img.example.com/photo.jpg?w=800&fm=webp 800w,
https://img.example.com/photo.jpg?w=1200&fm=webp 1200w
"
sizes="(max-width: 768px) 100vw, 800px"
alt="Hero image"
/>
If you want to self-host
Use Node.js with sharp:
- accept image URL or storage key
- validate allowed sizes and formats
- resize/convert
- cache response
Very small example:
import express from "express";
import sharp from "sharp";
import fetch from "node-fetch";
const app = express();
app.get("/img", async (req, res) => {
const { url, w, h, q = 80 } = req.query;
if (!url) return res.status(400).send("Missing url");
const resp = await fetch(url);
const input = Buffer.from(await resp.arrayBuffer());
let image = sharp(input).resize({
width: w ? Number(w) : undefined,
height: h ? Number(h) : undefined,
fit: "cover",
});
res.set("Content-Type", "image/webp");
image.webp({ quality: Number(q) }).pipe(res);
});
app.listen(3000);
Important considerations
- Validate input to prevent SSRF if you accept remote URLs
- Limit max dimensions to prevent abuse
- Strip metadata if privacy matters
- Preserve aspect ratio by default
- Generate multiple sizes for performance
- Use AVIF/WebP where supported
- Lazy load below-the-fold images
Practical recommendation
For a landing page builder, the fastest path is usually:
- Cloudinary/ImageKit/Imgix if you want simplicity and fewer ops
- Sharp + CDN if you want full control and lower long-term cost at scale
If you want, I can give you:
- a production-ready Node/Sharp image resizing API,
- a database + storage schema for your builder, or
- a frontend
srcsetgenerator for responsive images.