Does NanoImage CLI upload my images?
No. CLI processing happens entirely on your local machine. Files are never sent to any server.
Install and use NanoImage CLI to compress, resize, convert, and clean images from the command line.
NanoImage CLI is a command-line image optimization tool. It runs locally on your machine and processes files without any uploads.
CLI v1 includes five commands:
compress — Reduce image file sizeresize — Change image dimensionsconvert — Convert between formatswebp — Convert to WebPremove-exif — Strip metadataAll commands support single files and directories. For one file, --output can be a file path. For a folder, --output should be an output directory.
Requires Node.js 18 or later.
Install globally with npm:
npm install -g nanoimageOr use without installing:
npx nanoimage --helpVerify the install:
nanoimage --versionOne example for each command:
nanoimage compress photo.jpg --quality 75 --output photo-compressed.jpgnanoimage resize photo.jpg --width 1200 --output photo-1200.jpgnanoimage convert photo.png --to jpg --output photo.jpgnanoimage webp photo.jpg --quality 80 --output photo.webpnanoimage remove-exif photo.jpg --output photo-clean.jpgCompress an image or a folder of images.
nanoimage compress <input> [options]nanoimage compress photo.jpg --quality 75 --output photo-compressed.jpgnanoimage compress photo.jpg --target-kb 100 --output photo-100kb.jpgnanoimage compress ./images --quality 75 --output ./compressed| Option | Description |
|---|---|
--quality, -q | Output quality from 1 to 100 |
--target-kb | Best-effort target output size in KB |
--output, -o | Output file or directory |
--target-kb is best-effort. Some images may not reach the requested size without resizing or very low quality.Resize images by width or height. Aspect ratio is kept by default when only one dimension is provided.
nanoimage resize <input> [options]nanoimage resize photo.jpg --width 1200 --output photo-1200.jpgnanoimage resize photo.jpg --height 800 --output photo-800h.jpgnanoimage resize ./images --width 1600 --output ./resized| Option | Description |
|---|---|
--width, -w | Target width in px |
--height, -h | Target height in px |
--fit | Sharp fit mode: inside, contain, cover, fill, or outside |
--enlarge | Allow enlarging images smaller than the target size |
--output, -o | Output file or directory |
Convert images between common formats.
nanoimage convert <input> --to <format> [options]nanoimage convert input.png --to jpg --output output.jpgnanoimage convert logo.png --to jpg --background white --output logo.jpgnanoimage convert ./images --to webp --quality 80 --output ./converted| Option | Description |
|---|---|
--to | Target format: jpg, png, webp, or avif |
--output, -o | Output file or directory |
--quality, -q | Quality for JPG/WebP |
--background | Background color when converting transparency to JPG |
--background is specified.Convert images to WebP. This is a shortcut for a common web optimization workflow.
nanoimage webp <input> [options]nanoimage webp hero.jpg --quality 80 --output hero.webpnanoimage webp ./images --quality 82 --output ./webpnanoimage webp ./public/images --quality 82 --remove-exif --output ./public/images-webp| Option | Description |
|---|---|
--quality, -q | WebP quality from 1 to 100 |
--output, -o | Output file or directory |
--remove-exif | Remove metadata during conversion |
--quality to balance visual quality and output size.Remove common EXIF metadata from images. Useful before publishing personal, product, or website images.
nanoimage remove-exif <input> [options]nanoimage remove-exif photo.jpg --output photo-clean.jpgnanoimage remove-exif ./uploads --output ./uploads-clean| Option | Description |
|---|---|
--output, -o | Output file or directory |
All commands accept a directory as input. Pass a folder path and an output folder.
nanoimage compress ./images --quality 75 --output ./compressednanoimage resize ./images --width 1200 --output ./resizednanoimage webp ./images --quality 80 --output ./webpDirectory inputs are processed recursively by default.
--output can be a file path such as photo-compressed.jpg. For folder inputs, use an output directory such as ./compressed.Add --json to any command for machine-readable output. Useful for CI/CD, build scripts, logs, and AI agent workflows.
nanoimage compress photo.jpg --quality 75 --jsonExample output:
[
{
"input": "photo.jpg",
"output": "photo-compressed.jpg",
"inputSize": 2457600,
"outputSize": 524288
}
]Add NanoImage CLI to your package.json scripts:
{
"scripts": {
"optimize-images": "nanoimage compress ./public/images --quality 75 --output ./public/images-optimized"
}
}GitHub Actions example:
name: Optimize Images
on: [push]
jobs:
optimize:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install -g nanoimage
- run: nanoimage compress ./public/images --quality 75 --output ./public/images-optimized| Error | Meaning | Fix |
|---|---|---|
Unsupported format | Input format not supported | Use JPG, PNG, or WebP |
Cannot write output | Permission or path issue | Check folder permissions |
Input not found | File path is wrong | Check the input path |
Processing failed | Image decode/encode failed | Try another file or format |
No. CLI processing happens entirely on your local machine. Files are never sent to any server.
Yes. Use commands in npm scripts, build pipelines, or GitHub Actions. The --json flag gives machine-readable output for automation.
CLI v1 focuses on JPG, PNG, and WebP. More formats may be added in future versions.
Yes. Pass a directory as input and an output directory. Directories are processed recursively by default.