A command-line interface tool built with TypeScript for optimizing and downscaling images in bulk. This tool can process entire directories of images, optimizing them either by size or resolution.
- Bulk image processing
- Recursive directory scanning
- Two optimization modes:
- By Size: Reduce image file size to a specified maximum
- By Resolution: Downscale images to a maximum width and height
- Supports JPG, JPEG, and PNG formats
- Preserves directory structure in the output
- Detailed logging for transparency and debugging
- Node.js (version 14 or higher recommended)
- npm (comes with Node.js)
-
Clone the repository:
git clone https://github.com/yourusername/image-optimization-cli.git cd image-optimization-cli -
Install dependencies:
npm install -
Build the project:
npm run build
To start the CLI tool, run:
npm run serve
Follow the prompts to:
- Enter the source directory path
- Enter the destination directory path
- Choose the optimization method (By Size or By Resolution)
- Specify the optimization parameters (max size in MB or max width,height)
npm start: Run the CLI toolnpm run build: Compile TypeScript to JavaScriptnpm run serve: Run the compiled JavaScript version
src/
├── index.ts # Entry point
├── utils/
│ ├── terminal.js # Terminal prompt utilities
│ ├── logger.js # Logging utilities
│ ├── entry.js # Main application logic
│ ├── downScaleBySize.js
│ └── downScaleByResolution.js
- inquirer: For interactive command line user interfaces
- sharp: For high-performance image processing
- winston: For logging
- path: For file path operations
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.