Batch-compress JPEG photos with Sharp and MozJPEG. Keeps full resolution, reduces file size, and outputs .jpg files to compressed-photos/.
- Reads all
.jpg/.jpegfiles fromsource_photos/ - Compresses each photo without resizing
- Auto-rotates using EXIF orientation
- Strips metadata to save extra space
- Writes compressed files to
compressed-photos/with the same filename
Original files in source_photos/ are never modified.
- Node.js 18.17 or newer
npm install- Put your photos in
source_photos/ - Run:
npm run compress- Get compressed photos from
compressed-photos/
Example output:
DSC05215.JPG: 7.50 MB -> 3.76 MB (49.9% smaller)
Total: 51.25 MB -> 25.02 MB (51.2% smaller)
Saved to compressed-photos/
photo-compress/
├── source_photos/ # input photos (not committed)
├── compressed-photos/ # output photos (not committed)
├── compress-photos.js # compression script
└── package.json
Open compress-photos.js and change:
const JPEG_QUALITY = 75;- 90–95 — near-original look, larger files
- 75–85 — good balance for most photos
- Lower — smaller files, more visible compression
- JPEG compression is lossy. This tool aims for visually clean results, not bit-perfect lossless output.
- Re-running the script overwrites files in
compressed-photos/.