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

lab-minify

v0.2.1

Published

CLI for minifying image files in place with backups.

Readme

lab-minify

lab-minify is a Node.js CLI for minifying image files in place with backups.

lab-minify ./img
lab-minify photo.jpg

It optimizes the original files, keeps the same image formats, and creates a backup folder before replacing files. The target can be a directory or a single image file.

Features

  • Optimizes JPEG, PNG, WebP, and AVIF files.
  • Accepts a directory or a single image filename as the target.
  • Keeps the same format; it does not generate WebP or AVIF copies.
  • Creates backups beside the target directory, or in one shared folder for single-file targets.
  • Preserves nested folder structure inside the backup folder.
  • Replaces originals only when the optimized output is smaller by default.
  • Supports dry runs, recursive scans, and safe, balanced, and aggressive presets.
  • Shows live progress in interactive terminals while files are processed.
  • Skips SVG, GIF, ICO, XML, .filepart, and unknown file types.

Requirements

  • Node.js 20 or newer
  • npm 10 or newer

Install

Install globally if you want to run lab-minify from any project:

npm install -g lab-minify

Or run it without a global install:

npx lab-minify ./img

Usage

lab-minify ./img
lab-minify photo.jpg
lab-minify D:\absolute\path\to\photo.jpg
lab-minify /img/logo.png
lab-minify ./img --dry-run
lab-minify ./img --preset safe
lab-minify ./img --preset balanced
lab-minify ./img --preset aggressive
lab-minify ./img --no-recursive

Targets can be relative or absolute paths. On Windows, a leading-slash path like /img/logo.png falls back to the current folder when the drive-root path does not exist, so it works like ./img/logo.png. Quote paths that contain spaces.

Commands run immediately using the default options. Append flags when you want to change the defaults.

Options

| Option | Description | | --- | --- | | --dry-run | Optimizes in memory and prints estimated savings without writing files. | | --preset safe | Uses lighter compression. | | --preset balanced | Uses the default compression balance. | | --preset aggressive | Uses stronger compression with a higher chance of visible quality loss. | | --no-recursive | Only processes files directly inside the target folder. | | --formats jpg,png | Limits optimization to selected formats. | | --no-backup | Replaces files without creating backups. | | --replace-even-if-larger | Replaces files even if the optimized result is larger. |

Dry Runs

Use --dry-run before modifying a folder:

lab-minify ./img --dry-run

Dry runs scan files, optimize in memory, and print estimated savings. They do not replace files, create temporary files, or create backup folders.

Backup Behavior

For this command:

lab-minify ./img

The backup folder is created beside the target folder:

img-minify-bak

If that folder already exists, lab-minify creates a timestamped folder:

img-minify-bak-YYYYMMDD-HHMMSS

Only files that are actually replaced are backed up.

For a single-file target:

lab-minify photo.jpg

The backup folder is shared for single-file targets in the same folder:

single-files-minify-bak

If the same filename is backed up again, lab-minify keeps the backup in that same folder with a timestamped filename instead of creating another top-level backup folder.

Optimization Behavior

  • JPEG files are normalized with Sharp and compressed with Sharp's mozjpeg-compatible encoder options.
  • PNG files are normalized with Sharp and compressed with zlib plus palette quantization where the selected preset allows it.
  • WebP and AVIF files are optimized with Sharp.
  • Temporary files are written beside the original and then moved into place after successful optimization.
  • Animated images are skipped to avoid dropping frames.