devin-img-zip

Project Background

In modern web and full-stack development, static images are often too large, which slows down page loading and affects user experience. Manually compressing and replacing images is tedious, time-consuming, and error-prone. To address this pain point, I developed the imgzip npm package—a CLI tool for automated, batch image compression, greatly improving development efficiency and site performance.

Tech Stack

  • Language: JavaScript
  • Dependency: sharp
  • Package Manager: npm

Core Features

CLI Usage

imgzip [options]

Main Options

Option Description Example
-r, –root Specify the root directory to search images -r ./assets
-c, –compress <…> Only process images with these file names -c a.jpg b.png
-e, –exclude <…> Exclude images with these file names -e logo.png
-q, –quality Compression quality (1-100, default: 80) -q 90
-s, –size-limit Only process images larger than this size -s 1.5MB or -s 2048KB
  • If --compress is not specified, only images larger than the size limit will be processed.
  • Size limit supports MB (default), KB, B. E.g., 2MB, 2048KB, 2.5MB.
  • Compression overwrites the original files.
  • Supported formats: jpg, jpeg, png, webp.

Examples

  • Compress all images larger than 1.5MB in ./assets with quality 80:
imgzip -r ./assets -s 1.5MB -q 80
  • Compress all images larger than 1024KB in the current directory:
imgzip -s 1024KB
  • Only compress a.jpg and b.png in the current directory with quality 90:
imgzip -c a.jpg b.png -q 90

Project Structure

imgzip/
├── bin/                  # CLI entry
├── lib/                  # Core logic
├── package.json          # Package config
├── README.md             # Documentation
└── ...                   # Other files