Image Compression Guide โ From Zero to Automation
Whether you're occasionally compressing a passport photo or handling dozens of images every day for your website, this guide will double your efficiency. From the simplest methods to command-line automation, pick what fits your needs.
Getting Started: Online Compression โ Done in 3 Seconds
How to Use TinyPNG
tinypng.comUp to 20 images at a time, each under 5MB. If you have more, split them into batches. TinyPNG also has a Pro plan at $25/year that removes limits and provides an API โ but unless you're compressing hundreds of images daily, the free version is plenty.
How to Use Squoosh
squoosh.appA hidden Squoosh trick: you can stack multiple compression steps. For example, first convert PNG to WebP, then adjust WebP quality parameters, and finally resize. Layer by layer, the result is much better than using a single tool.
Intermediate: Batch Processing โ Stop Uploading One by One
Caesium (Windows/Mac/Linux)
saerasoft.com/caesiumRecommended settings: JPEG quality 75-85%, use lossy compression mode for PNG. Strip all metadata (EXIF/GPS info) โ it can save an extra 5-10% and protects your privacy, since photos taken with your phone may have GPS coordinates embedded.
ImageOptim (Mac Only)
A Mac-exclusive gem. Drag images or folders in and it processes them automatically. It uses lossless compression, so quality is unchanged โ it reduces file size by:
- Removing EXIF/GPS and other metadata
- Optimizing PNG encoding (using more efficient compression algorithms)
- Removing embedded thumbnails from JPEGs
- Optimizing GIF animations
Lossless compression rates are typically 20-40% โ not as much as lossy, but 100% quality retention. Ideal for archiving source files.
Advanced: Command-Line Automation
If you build websites or apps, image compression should be part of your build pipeline. Here are some excellent command-line tools:
pngquant โ Lossy PNG Compression
# Install
brew install pngquant # Mac
# Usage: single file
pngquant --quality=65-80 image.png --output image-compressed.png
# Batch: all PNGs in a folder
find . -name "*.png" -exec pngquant --quality=65-80 --ext .png --force {} \;
jpegoptim โ JPEG Optimization
brew install jpegoptim
# Compress to 80% quality
jpegoptim --max=80 image.jpg
# Batch + strip metadata
jpegoptim --max=80 --strip-all *.jpg
One-Click Compression Script (save as compress.sh)
#!/bin/bash
# Compress all images in the current folder
echo "Compressing PNGs..."
find . -name "*.png" -exec pngquant --quality=65-80 --ext .png --force {} \;
echo "Compressing JPEGs..."
find . -name "*.jpg" -o -name "*.jpeg" | while read f; do
jpegoptim --max=80 --strip-all "$f"
done
echo "All done!"
Place this script in your images folder, chmod +x compress.sh then ./compress.sh โ all images compressed automatically. For websites, integrate it into your CI/CD pipeline so compression happens on every deploy.
Website Image Optimization Best Practices
- Use WebP format โ It's 2024, all major browsers support it, and it's 25-35% smaller than JPEG
- Responsive images โ Use
<picture>tags orsrcsetto serve different sizes for different screens - Lazy loading โ The
loading="lazy"attribute loads images only when they scroll into view - CDN acceleration โ Serve images via CDN, closer to your users for faster loading
- Don't oversize images โ If your content area is 800px wide, don't serve a 1920px image. Resizing to the right dimensions can dramatically reduce file size