Skip to content

An CLI for aggressively reducing image file size with sane defaults. It's implemented on top of ImageMagick.

License

Notifications You must be signed in to change notification settings

microlinkhq/optimo

Repository files navigation


optimo

Powered by microlink.io Last version NPM Status

optimo reduces image file size aggressively, and safely.

Highlights

  • Format-specific tuning for stronger size reduction.
  • Safety guard: if optimized output is not smaller, original file is kept.
  • Backed by proven tools: ImageMagick, SVGO, Gifsicle, and MozJPEG.
  • Resizing supports percentage values (50%), max file size targets (100kB), width (w960), & height (h480).

Usage

npx -y optimo public/media            # for a directory
npx -y optimo public/media/banner.png # for a file
npx -y optimo public/media/banner.png --losy # enable lossy + lossless mode
npx -y optimo public/media/banner.png --format jpeg # convert + optimize
npx -y optimo public/media/banner.png --resize 50% # resize + optimize
npx -y optimo public/media/banner.png --resize 100kB # resize to max file size
npx -y optimo public/media/banner.png --resize w960 # resize to max width
npx -y optimo public/media/banner.png --resize h480 # resize to max height
npx -y optimo public/media/banner.heic --dry-run --verbose # inspect unsupported failures

Pipelines

When optimo is executed, a pipeline of compressors is chosen based on the output file format:

  • .png -> magick.png
  • .svg -> svgo.svg
  • .jpg/.jpeg -> magick.jpg/jpeg + mozjpegtran.jpg/jpeg
  • .gif -> magick.gif + gifsicle.gif
  • other formats (webp, avif, heic, heif, jxl, etc.) -> magick.<format>

Mode behavior:

  • default: lossless-first pipeline.
  • -l, --losy: lossy + lossless pass per matching compressor.
  • -v, --verbose: print debug logs (selected pipeline, binaries, executed commands, and errors).

Example output:

✓ banner.jpg  1.2MB → 348kB  (-71%)

If the optimized file isn’t smaller, the original is kept.

Programmatic API

const optimo = require('optimo')

// optimize a single file
await optimo.file('/absolute/path/image.jpg', {
  dryRun: false,
  losy: false,
  format: 'webp',
  resize: '50%',
  onLogs: console.log
})

await optimo.file('/absolute/path/image.jpg', {
  resize: '100kB',
  onLogs: console.log
})

await optimo.file('/absolute/path/image.jpg', {
  resize: 'w960',
  onLogs: console.log
})

// optimize a dir recursively
const result = await optimo.dir('/absolute/path/images')

console.log(result)
// {
//   originalSize: Number,
//   optimizedSize: Number,
//   savings: Number
// }

License

optimo © Microlink, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

microlink.io · GitHub microlinkhq · X @microlinkhq

About

An CLI for aggressively reducing image file size with sane defaults. It's implemented on top of ImageMagick.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published