picoptim
v1.0.0
Published
Resize AND optimise images on macOS. ImageOptim-CLI compresses but cannot resize — this does both in one command.
Maintainers
Readme
picoptim
Resize and optimise images, in one command. macOS only.
ImageOptim-CLI is excellent at squeezing bytes out of an image — but it cannot change an image's dimensions. That matters, because for most web work the resizing is where the savings actually come from:
4 photos straight off a phone/camera
6.74 MB → 0.87 MB (-87%)
resize 2268×4032 → 900×1600 ......... -83%
ImageOptim on top of that ........... -4%imgopt does the resample first (with sips, built into macOS, or ImageMagick if you have it) and then hands the results to ImageOptim.
Install
npm install -g picoptimYou also need ImageOptim.app itself — ImageOptim-CLI automates the GUI app, it does not reimplement it:
brew install --cask imageoptimOptional extras, picked up automatically when present:
| Tool | Why |
| --- | --- |
| ImageMagick (brew install imagemagick) | Better Lanczos resampling than sips |
| ImageAlpha | Lossy PNG via -a |
| JPEGmini | Extra JPEG compression via -j |
Usage
imgopt -m 1600 # longest side ≤ 1600px → ./optimized/
imgopt -w 1200 -o web *.jpg # max width 1200px → ./web/
imgopt -m 800 -i photos/ # overwrite the originals in photos/
imgopt -p 50 # scale to 50%
imgopt # optimise only, no resizing
imgopt -m 1600 -n # dry run: show the plan, write nothingOptions
Resize — never upscales an image that is already smaller than the target.
| Flag | Description |
| --- | --- |
| -m, --max N | Longest side at most N px |
| -w, --width N | Max width N px |
| -H, --height N | Max height N px |
| -p, --percent N | Scale to N% of the original |
Output
| Flag | Description |
| --- | --- |
| -o, --out DIR | Destination directory (default: ./optimized) |
| -i, --in-place | Overwrite the originals — no copy is kept |
Optimisation
| Flag | Description |
| --- | --- |
| -a, --imagealpha | Enable ImageAlpha (lossy PNG, much smaller) |
| -j, --jpegmini | Enable JPEGmini |
| -q, --quality MIN-MAX | ImageAlpha quality 0–100 (default 65-80) |
| -R, --no-optimize | Resize only, skip ImageOptim |
Other
| Flag | Description |
| --- | --- |
| -r, --recursive | Include images in subdirectories |
| --engine E | sips, magick or auto (default auto) |
| -n, --dry-run | Show what would happen, write nothing |
| -h, --help / -V, --version | |
Supported formats: JPEG, PNG, GIF, TIFF.
Design notes
Originals are never touched by default. Output goes to ./optimized/. ImageOptim overwrites in place with no undo — combine that with a downscale and the original is gone for good. -i opts into that behaviour explicitly.
No upscaling. An 800px image asked to fit in a 1600px box is left at 800px, rather than being interpolated up to a blurrier, larger file.
Aspect ratio is preserved. -m/-w/-H define a box to fit inside; the scale factor is computed from whichever constraint binds first.
Why not just ImageMagick?
You can absolutely do magick mogrify -resize 1600x1600\> *.jpg. What you don't get is the ImageOptim pass — the lossless zopfli/pngout/jpegoptim work that shaves the last few percent — nor the safe-by-default output directory, the no-upscale rule, or the before/after accounting. imgopt is the two halves wired together with sensible defaults.
Requirements
- macOS (uses
sipsand drives ImageOptim.app) - Node.js ≥ 14 (to install via npm)
- ImageOptim.app
License
MIT © Bruno Pinheiro
