oi-optimize
v1.0.0
Published
Fast image optimizer CLI — compress, resize, and convert JPG, PNG, WebP, AVIF, TIFF, and GIF in bulk. Powered by sharp with mozjpeg. Zero config.
Maintainers
Readme
oi-optimize
Fast image optimizer CLI — compress, resize, and convert JPG, PNG, WebP, AVIF, TIFF, and GIF in bulk. Powered by
sharpwith mozjpeg. Zero config.
A simple, zero-config command-line tool for bulk image optimization. Point it at a file or folder, and it will compress, resize, and/or convert every image it finds — recursively — with a single command.
Features
- 🗜 Compress JPG, PNG, WebP, AVIF, TIFF, and GIF with tunable quality
- 🔁 Convert between formats in one pass (e.g. JPG → WebP, PNG → AVIF)
- 📐 Resize with aspect-preserving fit (no enlargement)
- 📂 Recursive — walks directories and processes every image
- 🚀 Fast — built on
sharpwithmozjpegencoding - 📊 Reports savings — shows before/after size and percentage saved
- 🧰 Zero config — sensible defaults out of the box
Installation
Install globally with npm:
npm install -g oi-optimizeOr run ad-hoc without installing:
npx oi-optimize ./imagesUsage
oi <path> [options]<path> can be a single image file or a directory (walked recursively).
Options
| Flag | Description | Default |
| --- | --- | --- |
| -q, --quality <1-100> | Output quality | 80 |
| -f, --format <fmt> | Output format: original, jpg, png, webp, avif, tiff, gif | original |
| -s, --size <WxH> | Resize to width × height (keeps aspect, won't enlarge) | — |
| -d, --delete-original | Delete source files after converting to a different format | false |
| -h, --help | Show help | — |
Examples
Optimize every image in a folder with defaults (quality 80, keep format):
oi ./imagesStronger compression — quality 60:
oi ./images -q 60Convert everything to WebP:
oi ./images -f webpConvert to AVIF and delete the original files:
oi ./images -f avif -dResize and convert to PNG at quality 90:
oi ./images -q 90 -f png -s 800x600Optimize a single file:
oi ./hero.jpg -q 75Supported formats
Input: jpg, jpeg, png, webp, avif, tiff, tif, gif
Output: same, plus cross-format conversion.
How it works
oi wraps sharp with opinionated encoder settings:
- JPEG →
mozjpeg(better compression than stock libjpeg) - PNG → compression level 9, effort 10
- WebP / AVIF / TIFF → quality-tunable lossy encoding
- GIF → passthrough
Resizing uses fit: "inside" with withoutEnlargement: true, so small images are never upscaled.
Files are written atomically through a temporary .oi_tmp file, so an interrupted run won't leave corrupt output.
Requirements
- Node.js ≥ 18
License
MIT © Rubel Hossain
