Lightweight image compression command-line tool based on tinypng.com API.
English | 中文
- 📂 Batch Processing: Supports batch compression with simple
globpattern 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 keyusage. - 🗂️ 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.
npm i @zd~/tinify -gAfter installation, you can directly use the tinify command.
| Command Example | Description |
|---|---|
tinify --help |
Display help information |
tinify --version |
Display version information |
tinify init <key> |
Initialize and set API key |
tinify <glob-pattern> |
Compress matched image files |
tinify -n <glob-pattern> |
Compress files without overwriting |
tinify --key <key> <glob-pattern> |
Use specified key for compression (overrides global key) |
tinify --no-over <glob-pattern> |
No-overwrite mode |
tinify --limit 10 <glob-pattern> |
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 |
| Parameter | Description |
|---|---|
-h, --help |
Display help information |
-v, --version |
Display version information |
-k, --key <key> |
Set API key |
-n, --no-over |
No-overwrite mode, default is overwrite |
-o, --output <dir> |
Output directory, default tinify-output (in no-overwrite mode) |
-l, --limit <num> |
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 |
Visit https://tinypng.com/developers to apply for a free API Key.
tinify init <your_key>
tinify "images/**/*.png"
tinify --no-over "assets/*.jpg"
tinify --key <your_key> "imgs/*.webp"- Free users can compress
500images per month. After exceeding the limit, you need to wait for the next month's reset or upgrade to a paid plan. - The
<glob-pattern>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-overparameter and optionally use--outputto specify output directory (default: tinify-output). - It's recommended to set the
--limitparameter to improve compression speed. Default concurrency is10. - User configuration file is located at
~/.zd.tinify. You can manually edit this file to modify theAPI Key. - Compression cache files are located at
~/.zd.tinify/.cache. Use--clear-cacheparameter to delete all cache (cache uses hash sharding, theoretically won't occupy too much space).
MIT
