npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@valdiszz53/image-optimizer-cli

v1.0.0

Published

CLI package for optimizing images from a directory

Readme

Image Optimizer CLI

A fast and flexible CLI tool for optimizing images, converting formats and resizing images based on filename instructions or project configuration.

Features

  • 🚀 Optimize JPEG, PNG, WebP, AVIF and SVG images
  • 📁 Recursive directory scanning
  • 📂 Preserve folder structure
  • 🖼 Convert images to multiple formats
  • 📏 Resize images directly from filename
  • 📉 Configurable compression quality
  • ⚙️ Project configuration file
  • 💻 CLI arguments
  • 🔍 Dry-run mode
  • 🧹 Clean output directory
  • 📊 Processing statistics
  • ⚡ Powered by Sharp

Installation

# Global
npm install -g image-optimizer-cli

# Using npx
npx image-optimizer-cli ./images

# Local
npm install image-optimizer-cli
# or
npm install
npm link

Usage

image-optimizer [input-directory] [options]

The input directory can be provided either:

  • as the first CLI argument;
  • in the configuration file (inputDir).

Examples

Optimize images:

image-optimizer ./images

Save into another directory:

image-optimizer ./images \
    --output ./dist

Convert every image to WebP:

image-optimizer ./images \
    --format webp

Change quality:

image-optimizer ./images \
    --quality 70

Dry run:

image-optimizer ./images \
    --dry-run

Use custom configuration:

image-optimizer \
    --config ./configs/image-optimizer.config.ts

Configuration

Create a file:

image-optimizer.config.ts

Example:

import { defineConfig } from 'image-optimizer'

export default defineConfig({
    inputDir: './assets',
    outputDir: './public/assets',
    quality: 80,
    clean: true,
    outputs: {
        jpg: ['jpeg', 'webp'],
        jpeg: ['jpeg', 'webp'],
        png: ['png', 'webp'],
        webp: ['webp'],
        avif: ['avif'],
        svg: ['svg'],
    },
})

With this configuration:

logo.png

becomes

logo.png
logo.webp

without adding any filename instructions.

CLI Options

| Option | Description | | --------------- | ---------------------------------------- | | -c, --config | Path to configuration file | | -o, --output | Output directory | | -q, --quality | Compression quality (1–100) | | -f, --format | Force output format | | --dry-run | Show processing without writing files | | --clean | Clean output directory before processing |

Supported Formats

  • JPG
  • JPEG
  • PNG
  • WebP
  • AVIF
  • SVG
  • TIFF

Filename Instructions

Filename instructions always override both CLI arguments and configuration.

Example:

logo[120].png
↓
logo.png

Resize

| Instruction | Result | | ------------------ | ---------------------------- | | logo[120].png | width = 120px | | logo[120x80].png | width = 120px, height = 80px | | logo[w=120].png | width = 120px | | logo[h=80].png | height = 80px | | logo[50%].png | resize to 50% | | logo[2x].png | scale ×2 |

Format Conversion

Convert:

photo[webp].png
↓
photo.webp

Keep original:

photo[+webp].png
↓
photo.png
photo.webp

Generate multiple formats:

photo[+webp,+avif].png
↓
photo.png
photo.webp
photo.avif

Resize + convert:

photo[320.webp].png
↓
photo.webp # width 320px

Resize + keep original:

photo[320.+webp].png
↓
photo.png
photo.webp

Both images will be resized.

Per-image quality:

photo[q=60].jpg
or
photo[quality=60].jpg

SVG Support

SVG files are never rasterized.

Supported:

logo[24].svg
↓
<svg width="24px"/>
logo[24x24].svg
↓
<svg
    width="24px"
    height="24px"/>

Configuration Priority

Image Optimizer resolves settings using the following priority:

  1. Filename instructions
  2. CLI arguments
  3. Configuration file
  4. Default values

Example:

Configuration:

outputs: {
    png: ['png', 'webp']
}

Image:

logo.png
↓
logo.png
logo.webp

But:

logo[avif].png
↓
logo.avif

because filename instructions always have the highest priority.

Folder Structure

Input:

images
├── logo[120].png
├── hero.jpg
└── icons
    ├── menu[32].svg
    └── close.png

Configuration:

export default defineConfig({
    outputDir: './dist',
    outputs: {
        png: ['png', 'webp'],
        jpg: ['jpeg'],
    },
})

Output:

dist
├── logo.png
├── logo.webp
├── hero.jpeg
└── icons
    ├── menu.svg
    ├── close.png
    └── close.webp

The directory structure is always preserved.

Processing Statistics

Example output:

Found 42 image(s)

✓ logo.png      420 KB → 95 KB (-77%)
✓ logo.webp     420 KB → 62 KB (-85%)
✓ hero.jpeg     1.8 MB → 640 KB (-64%)

Summary
────────────────────────────
Processed: 63
Skipped:   0
Before:    24.7 MB
After:     10.2 MB
Saved:     14.5 MB

Example Workflow

Configuration:

export default defineConfig({
    inputDir: './assets',
    outputDir: './public/assets',
    outputs: {
        png: ['png', 'webp'],
        jpg: ['jpeg', 'webp'],
    },
})

Assets:

assets
├── logo.png
├── hero.jpg
├── avatar[50%].png
├── icon[32].svg
├── banner[+avif].jpg

Result:

public/assets
├── logo.png
├── logo.webp
├── hero.jpeg
├── hero.webp
├── avatar.png
├── avatar.webp
├── icon.svg
├── banner.jpg
└── banner.avif

Requirements

  • Node.js 18+
  • Sharp 0.33+

License

MIT