optimize-public-images
v1.0.2
Published
Development tool to optimize images in Next.js public folder subdirectories by creating _optimized copies in WebP format.
Maintainers
Readme
🚀 Optimize Public Images
A powerful, interactive CLI tool to optimize images in your Next.js public folder. Convert images to WebP format with an intuitive selection interface and flexible optimization strategies.
Features
✨ Interactive Selection
- Optimize all images at once
- Select by folder (and subfolders)
- Select individual files with checkboxes
🎯 Flexible Strategies
- New Folder: Create optimized copies in separate folders (customizable suffix)
- Overwrite: Place optimized WebP files alongside originals
🖼️ Image Support
- JPG, JPEG, PNG, GIF, SVG
🎨 Professional UI
- Colored terminal output
- Progress spinners
- Clear success/error reporting
Installation
As a Dev Dependency
npm install --save-dev optimize-public-imagesThen run:
npx optimize-publicAs a Global Package
npm install -g optimize-public-imagesThen run from any project:
optimize-publicUsage
Run the Interactive CLI
npx optimize-publicor globally:
optimize-publicHelp
optimize-public --helpHow It Works
- Scan: Auto-detects your Next.js
publicfolder - Select: Choose which images to optimize (all, by folder, or individual files)
- Configure: Pick your strategy (new folder or overwrite)
- Optimize: Converts images to WebP format with quality set to 80
Example Folder Structure
Before:
public/
├── logo.png
├── images/
│ ├── hero.jpg
│ ├── card.png
│ └── icon.svg
└── icons/
├── home.png
└── user.pngAfter (New Folder Strategy with _optimized suffix):
public/
├── logo.png
├── _optimized/
│ └── logo.webp
├── images/
│ ├── hero.jpg
│ ├── card.png
│ └── icon.svg
├── images_optimized/
│ ├── hero.webp
│ ├── card.webp
│ └── icon.webp
└── icons/
├── home.png
└── user.png(Note: SVG files are not converted to WebP; only raster images are optimized)
Requirements
- Node.js 12.0+
- A Next.js project with a
publicfolder
Dependencies
- sharp: Image processing
- glob: File pattern matching
- inquirer: Interactive CLI prompts
- chalk: Colored terminal output
- ora: Loading spinners
- fs-extra: File system utilities
Performance
Optimizing to WebP typically reduces image sizes by 25-35% compared to PNG/JPG.
License
MIT
Author
Your Name
Support
For issues or feature requests, visit the GitHub repository.
