Optimize and convert images using the optimo CLI and API on top of ImageMagick. Use when the user mentions reducing image size, image compression, batch image optimization, converting formats (jpeg/png/webp/avif/heic/jxl), resizing by percentage/dimensions/max-size, or running optimo in scripts.
Instal·la
npx skillscat add microlinkhq/skills/optimo Instal·la des del registre de SkillsCat.
optimo
optimo reduces image size with a format-specific compression pipeline.
Prerequisites
optimo resolves compressors from PATH and throws if required binaries are missing.
Required by format:
- all ImageMagick-backed formats:
magick - SVG pipeline:
svgo - JPEG second pass:
mozjpegtranorjpegtran - GIF second pass:
gifsicle
Quick Start (CLI)
Use npx for one-off runs:
npx -y optimo public/mediaOptimize a single file:
npx -y optimo public/media/banner.pngRun a dry run (no file changes):
npx -y optimo public/media/banner.png --dry-run # long version
npx -y optimo public/media/banner.png -d # short versionEnable lossy mode:
npx -y optimo public/media/banner.jpg --losy # long version
npx -y optimo public/media/banner.jpg -l # short versionConvert and optimize to a new format:
npx -y optimo public/media/banner.png --format jpeg # long version
npx -y optimo public/media/banner.png -f jpeg # short versionResize by percentage:
npx -y optimo public/media/banner.png --resize 50% # long version
npx -y optimo public/media/banner.png -r 50% # short versionResize to a target max file size:
npx -y optimo public/media/banner.png --resize 100kB # long version
npx -y optimo public/media/banner.png -r 100kB # short versionResize by width:
npx -y optimo public/media/banner.png --resize w960 # long version
npx -y optimo public/media/banner.png -r w960 # short versionResize by height:
npx -y optimo public/media/banner.png --resize h480 # long version
npx -y optimo public/media/banner.png -r h480 # short versionEnable verbose debugging:
npx -y optimo public/media/banner.heic --dry-run --verbose # long version
npx -y optimo public/media/banner.heic -d -v # short versionPipelines
optimo selects a pipeline by output 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
--losy/-l: lossy + lossless pass where supported
Recommended Workflow
- Start with
--dry-runto confirm target files. - Run optimization on one file first, then scale to directories.
- Use
--formatonly when conversion is intended. - Use
--resizeonly when explicit dimension/size control is required. - Use
--verbosewhen diagnosing unsupported files or binary/flag issues. - Verify outputs in version control before committing.
CLI Options
-d,--dry-run: Show what would change without writing files.-f,--format: Convert output format (jpeg,webp,avif, etc.).-l,--losy: Enable lossy + lossless pass.-r,--resize: Resize using percentage (50%), max file size (100kB), width (w960), or height (h480).-s,--silent: Suppress per-file logs.-v,--verbose: Print debug logs (pipeline selection, command execution, and errors).
Programmatic API
const optimo = require('optimo')
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
})
const result = await optimo.dir('/absolute/path/images')
console.log(result)
// { originalSize, optimizedSize, savings }Behavior Notes
- For non-conversion runs, if the optimized file is not smaller, the original file is kept.
- During conversion, output uses the new extension and the original source file is removed (unless
--dry-run). - Hidden files and folders (names starting with
.) are skipped in directory mode. - Unsupported files are reported as
[unsupported]and ignored.