Prompt

How do I set up on-the-fly image resizing for my site?

Technology / CDN & Edge Infrastructure1 observationLast seen Oct 4, 2026

Latest observation

Oct 4, 2026OpenAI APIWeb search: off

On-the-fly image resizing means your site can request images in different sizes as needed, and the server/CDN generates or serves the right version dynamically. The most common ways to do it are:

1) Use an image CDN/service

This is the easiest option.

Examples:

  • Cloudinary
  • Imgix
  • ImageKit
  • Fastly Image Optimizer
  • Cloudflare Images / Polish / Image Resizing

Typical flow:

  1. Upload original images.
  2. Request variants via URL parameters, e.g. width/height/format/quality.
  3. The service resizes, caches, and delivers optimized images.

Example:

<img src="https://example.imgix.net/photo.jpg?w=800&h=600&fit=crop&auto=format,compress" />

Pros:

  • Fast to set up
  • Built-in caching and optimization
  • Often supports WebP/AVIF, cropping, sharpening, responsive delivery

Cons:

  • Monthly cost
  • Vendor dependency

2) Use your own server with dynamic resizing

If you want to host it yourself, your app can resize images on request.

Common stacks:

  • Node.js: sharp
  • Python: Pillow
  • PHP: Intervention Image / Imagick
  • Go: imaging libraries
  • Nginx + image module / backend handler

Example approach

Request format:

/images/photo.jpg?width=800&height=600&format=webp

Backend steps:

  1. Read the source image
  2. Validate requested dimensions
  3. Resize/crop
  4. Convert format if needed
  5. Cache the result
  6. Return the transformed image

Node.js example with Sharp

import express from "express";
import sharp from "sharp";
import fs from "fs";

const app = express();

app.get("/images/:name", async (req, res) => {
  const { name } = req.params;
  const width = parseInt(req.query.width, 10);
  const height = parseInt(req.query.height, 10);

  const filePath = `./images/${name}`;

  if (!fs.existsSync(filePath)) {
    return res.status(404).send("Not found");
  }

  let image = sharp(filePath);

  if (width || height) {
    image = image.resize(width || null, height || null);
  }

  const format = (req.query.format || "jpeg").toString();

  if (format === "webp") image = image.webp();
  else if (format === "png") image = image.png();
  else image = image.jpeg();

  res.type(`image/${format}`);
  image.pipe(res);
});

app.listen(3000);

Pros:

  • Full control
  • No external service required

Cons:

  • More maintenance
  • Need caching and security controls
  • Can be CPU-heavy

3) Use responsive images in HTML

Even if you use a resizing service/backend, you should serve the right size to the browser.

Use:

  • srcset
  • sizes

Example:

<img
  src="/images/photo.jpg?w=800"
  srcset="
    /images/photo.jpg?w=400 400w,
    /images/photo.jpg?w=800 800w,
    /images/photo.jpg?w=1200 1200w
  "
  sizes="(max-width: 600px) 400px, (max-width: 1000px) 800px, 1200px"
  alt="Example"
/>

This lets the browser pick the best size for the viewport and device pixel ratio.


4) Add caching

This is essential for on-the-fly resizing.

Use:

  • CDN caching
  • Browser caching headers
  • Server-side disk/memory cache

Recommended headers:

Cache-Control: public, max-age=31536000, immutable

If the URL contains all transformation parameters, each variant can be cached separately.


5) Protect against abuse

Dynamic resizing can be expensive.

Add:

  • Limits on max width/height
  • Allowed formats only
  • Allowed source paths
  • Rate limiting
  • Signed URLs or tokens if needed

Example restrictions:

  • Width max 2000 px
  • Height max 2000 px
  • Only JPEG/PNG/WebP output
  • Reject arbitrary remote URLs unless explicitly supported

Recommended setup

For most sites:

  1. Put originals in object storage or your media folder
  2. Use a resizing service or sharp on your backend
  3. Serve images through transform URLs
  4. Use srcset and sizes
  5. Cache aggressively at CDN/browser level

If you tell me your stack

I can give you a ready-to-use setup for:

  • WordPress
  • Next.js
  • React
  • Node/Express
  • Python/Django/Flask
  • Laravel
  • Nginx/Apache
  • Cloudflare/Cloudinary/Imgix

If you want, I can provide a complete implementation example for your specific stack.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.