Prompt
I'm building a tool that lets users upload photos, how should I compress them?
Latest observation
Oct 20, 2026
OpenAI APIWeb search: off
For photo uploads, the best compression approach is usually:
1) Re-encode server-side
Don’t rely only on the original file. After upload, generate optimized derivatives:
- Keep original for archival/reprocessing if needed
- Store display versions at the sizes you actually use
- Strip metadata unless you need it
2) Resize before compressing
Most uploaded photos are far larger than needed.
- Make multiple sizes, e.g. thumbnail / medium / large
- Don’t serve a 4000×3000 image if the UI only shows 1200px wide
- Preserve aspect ratio
3) Use modern formats when possible
Recommended output order:
- AVIF: best compression, slower encode, great for web
- WebP: excellent balance, widely supported
- JPEG: fallback for compatibility
Typical strategy:
- Serve AVIF/WebP to supported browsers
- Fall back to JPEG for others
4) Use the right quality settings
Good starting points:
- JPEG quality: 75–85
- WebP quality: 70–80
- AVIF quality: adjust by testing; often lower numeric quality than JPEG still looks good
If you want a simple rule:
- Start at 80
- Lower until you notice visible artifacts
- Keep faces and text-based images at a higher quality if needed
5) Strip unnecessary metadata
Remove:
- EXIF
- GPS data
- Camera model
- Orientation tags after normalizing rotation
This reduces size and protects privacy.
6) Normalize orientation
Many phone photos have EXIF orientation tags instead of physically rotated pixels.
- Read EXIF orientation
- Rotate pixels correctly
- Then remove EXIF
7) Consider a CDN/image service
If possible, use a service or pipeline that can:
- Resize on demand
- Convert to AVIF/WebP
- Cache efficiently
- Deliver responsive images
Examples: Cloudflare Images, imgix, Cloudinary, Fastly Image Optimizer, or your own pipeline.
8) Suggested implementation flow
- User uploads original
- Validate file type and size
- Decode image
- Auto-rotate using EXIF
- Strip metadata
- Generate variants:
- thumbnail
- medium
- large
- Encode to AVIF/WebP/JPEG
- Store originals + derivatives
- Serve the best format via
srcset/ content negotiation
9) Practical defaults
If you want a straightforward default setup:
- Max upload dimension: 4096 px
- Stored display sizes: 320, 768, 1200, 1600 px
- JPEG quality: 82
- WebP quality: 78
- AVIF quality: 45–55 to start
- Strip EXIF metadata except maybe orientation before processing
- Resize only down, never up
10) Don’t compress everything the same way
Different images need different handling:
- Photos: WebP/AVIF/JPEG
- Screenshots/UI captures: PNG or lossless WebP/AVIF may be better
- Transparent images: WebP/AVIF, or PNG fallback
If you want, I can also give you:
- a recommended compression pipeline for Node/Python/Go
- sample code using Sharp
- or a best-practice upload architecture for your app