Prompt
I'm building a blog and want every uploaded image converted to WebP automatically
Latest observation
Nov 2, 2026
OpenAI APIWeb search: off
You can do this reliably by converting images on upload in your backend, then storing the WebP version as the canonical file.
Typical approach
- User uploads image
- Server receives file
- Validate file type/size
- Convert to WebP
- Save WebP
- Return the WebP URL
- Optionally delete the original upload
Example: Node.js with Sharp
import express from "express";
import multer from "multer";
import sharp from "sharp";
import fs from "fs/promises";
import path from "path";
const app = express();
const upload = multer({ dest: "uploads/" });
app.post("/upload", upload.single("image"), async (req, res) => {
try {
if (!req.file) return res.status(400).json({ error: "No file uploaded" });
const inputPath = req.file.path;
const outputFileName = `${req.file.filename}.webp`;
const outputPath = path.join("public/uploads", outputFileName);
await sharp(inputPath)
.webp({ quality: 80 })
.toFile(outputPath);
await fs.unlink(inputPath); // remove temp file
res.json({
success: true,
url: `/uploads/${outputFileName}`,
});
} catch (err) {
console.error(err);
res.status(500).json({ error: "Image conversion failed" });
}
});
app.listen(3000, () => console.log("Server running on port 3000"));
Notes
- Use Sharp for Node.js—it’s fast and widely used.
- Set quality around
75–85for a good balance. - Preserve transparency: WebP supports alpha.
- Handle animated GIFs carefully: Sharp may not preserve animation unless configured specifically; if you need that, mention it.
- Keep originals only if needed for reprocessing later.
If you use another stack
I can give you the same setup for:
- Next.js
- Laravel / PHP
- Django / Python
- Rails
- WordPress
- S3 / cloud storage pipeline
If you want, I can also show you how to:
- generate multiple sizes
- keep the original and WebP
- create a reusable upload middleware
- auto-convert images in a serverless setup