Prompt
How do I automatically resize images on upload?
Latest observation
Nov 2, 2026
OpenAI APIWeb search: off
You can automatically resize images on upload in a few common ways, depending on where your app runs.
Common approaches
1) Resize on the backend after upload
Flow:
- User uploads image
- Server receives it
- Server resizes it with an image library
- Save the resized version
This is the most common approach if you control the backend.
Examples of libraries:
- Node.js:
sharp - Python:
Pillow - PHP:
Intervention Image - Ruby:
mini_magick
2) Resize in the browser before uploading
Flow:
- User selects image
- JavaScript resizes it locally
- Upload the smaller version
Good for saving bandwidth and speeding up uploads, but you still may want server-side validation.
3) Use an image service/CDN
Services like:
- Cloudinary
- Imgix
- Uploadcare
- Firebase Extensions / Functions
They can resize on upload or on demand.
Example: Node.js with Sharp
const express = require('express');
const multer = require('multer');
const sharp = require('sharp');
const upload = multer({ storage: multer.memoryStorage() });
const app = express();
app.post('/upload', upload.single('image'), async (req, res) => {
try {
const resized = await sharp(req.file.buffer)
.resize(800, 800, {
fit: 'inside',
withoutEnlargement: true
})
.toBuffer();
// save `resized` to disk, S3, etc.
res.send('Image resized and ready to save');
} catch (err) {
res.status(500).send('Error resizing image');
}
});
app.listen(3000);
Example: Python with Pillow
from PIL import Image
from flask import Flask, request
import io
app = Flask(__name__)
@app.route('/upload', methods=['POST'])
def upload():
file = request.files['image']
img = Image.open(file.stream)
img.thumbnail((800, 800)) # keeps aspect ratio
output = io.BytesIO()
img.save(output, format=img.format)
output.seek(0)
# save output to disk/cloud
return "Image resized"
app.run()
Tips
- Preserve aspect ratio unless you specifically want cropping.
- Limit maximum dimensions and file size.
- Validate file type before processing.
- Consider generating multiple sizes (thumbnail, medium, full).
- If using thumbnails, keep originals too if needed.
If you tell me your stack (e.g. React, Node, Django, Laravel, WordPress), I can show you the exact implementation.