npm install @zd~/tinify

Lightweight image compression command-line tool based on tinypng.com API.
---
- 📂 Batch Processing: Supports batch compression with simple glob pattern matching.
- ⚡ High-Speed Concurrency: Supports concurrent batch compression with default concurrency of 10, flexibly adjustable via parameters.
- 🔄 Multiple Modes: Choose between overwriting original images or preserving them.
- 💾 Save Your Key: Supports caching compressed images to avoid duplicate compression, improving efficiency and maximizing your tinypng key usage.
- 🗂️ Custom Output: Supports specifying output directory for convenient management of compressed images.
---
Make sure you have an API Key from https://tinypng.com/developers. Free users can compress 500 images per month.
---
bash
npm i @zd~/tinify -g
`After installation, you can directly use the
tinify command.---
Usage
| Command Example | Description |
|-------------------------------------------------------------------|------------------------------------------------|
| tinify --help | Display help information |
| tinify --version | Display version information |
| tinify init | Initialize and set API key |
| tinify | Compress matched image files |
| tinify -n | Compress files without overwriting |
| tinify --key | Use specified key for compression (overrides global key) |
| tinify --no-over | No-overwrite mode |
| tinify --limit 10 | Concurrency limit, default 10 (recommended for speed) |
| tinify --force | Force compression, ignore all previously compressed images, default false |
| tinify --clear-cache | Clear all compression cache |
| tinify --show-key | Display API Key |---
Parameters
| Parameter | Description |
|-----------------------------|--------------------------------------------------|
| -h, --help | Display help information |
| -v, --version | Display version information |
| -k, --key | Set API key |
| -n, --no-over | No-overwrite mode, default is overwrite |
| -o, --output | Output directory, default tinify-output (in no-overwrite mode) |
| -l, --limit | Concurrency limit, default 10 (recommended for speed) |
| -f, --force | Force compression, ignore all previously compressed images |
| -c, --clear-cache | Clear all compression cache |
| -s, --show-key | Display API Key |---
Getting API Key
Visit https://tinypng.com/developers to apply for a free API Key.
---
Examples
`bash
tinify init
tinify "images/*/.png"
tinify --no-over "assets/*.jpg"
tinify --key "imgs/*.webp"
`---
Notes
- Free users can compress 500 images per month. After exceeding the limit, you need to wait for the next month's reset or upgrade to a paid plan.
- The parameter defaults to */.(png|jpeg|jpg|gif|webp). You can adjust as needed, refer to fast-glob.
- By default, original images will be overwritten. If you don't want to overwrite, use the --no-over parameter and optionally use --output to specify output directory (default: tinify-output).
- It's recommended to set the --limit parameter to improve compression speed. Default concurrency is 10.
- User configuration file is located at ~/.zd.tinify. You can manually edit this file to modify the API Key.
- Compression cache files are located at ~/.zd.tinify/.cache. Use --clear-cache` parameter to delete all cache (cache uses hash sharding, theoretically won't occupy too much space).---