Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gaohaoyang/compress-pics
A tool to compress pictures
https://github.com/gaohaoyang/compress-pics
compress-images tinypng
Last synced: 2 days ago
JSON representation
A tool to compress pictures
- Host: GitHub
- URL: https://github.com/gaohaoyang/compress-pics
- Owner: Gaohaoyang
- License: mit
- Created: 2023-12-14T20:03:17.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-05-10T16:47:25.000Z (6 months ago)
- Last Synced: 2024-05-10T17:51:29.222Z (6 months ago)
- Topics: compress-images, tinypng
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/compress-pics
- Size: 2.2 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![GitHub License](https://img.shields.io/github/license/gaohaoyang/compress-pics?color=blue)](https://github.com/Gaohaoyang/compress-pics/blob/main/LICENSE) [![npm](https://img.shields.io/npm/v/compress-pics)](https://www.npmjs.com/package/compress-pics) [![GitHub issues](https://img.shields.io/github/issues/gaohaoyang/compress-pics)](https://github.com/Gaohaoyang/compress-pics/issues) [![GitHub pull requests](https://img.shields.io/github/issues-pr/gaohaoyang/compress-pics)](https://github.com/Gaohaoyang/compress-pics/pulls)
A command-line tool that uses the tinyPNG API to compress images. It simplifies the process of batch compressing images with tinyPNG in any directory of your project.
Of course, you need to apply a tinyPNG API Key first, it's free and convenient.
![](./assets/compress-pics.png)
- [Install](#install)
- [Usage](#usage)
- [Additional information](#additional-information)
- [What if it show an error while compressing?](#what-if-it-show-an-error-while-compressing)
- [Contribution](#contribution)## Install
```bash
npm i compress-pics -D
```or
```bash
yarn add compress-pics -D
```or
```bash
pnpm i compress-pics -D
```## Usage
In your `package.json` file, add the following script:
```json
{
"scripts": {
"compress-pics": "compress-pics"
}
}
```Then run in your project directory:
```bash
npm run compress-pics
```or
```bash
yarn compress-pics
```Then, you will see the following prompt:
```
____ ____ _
/ ___| ___ _ __ ___ _ __ _ __ ___ ___ ___ | _ \ (_) ___ ___
| | / _ \ | '_ ` _ \ | '_ \ | '__|/ _ \/ __|/ __| | |_) || | / __|/ __|
| |___| (_) || | | | | || |_) || | | __/\__ \\__ \ | __/ | || (__ \__ \
\____|\___/ |_| |_| |_|| .__/ |_| \___||___/|___/ |_| |_| \___||___/
|_|? Select your images directory: (Use arrow keys or type to search)
❯ ./
assets
bin
dist
src
```After selecting the image directory, you will see the following prompt:
```
? Select your images directory: assets
Your images directory is: assets
┌────────────────────────────┬───────┬──────────┬─────────────┐
│ │ Count │ Size(MB) │ Size(Bytes) │
├────────────────────────────┼───────┼──────────┼─────────────┤
│ canBeCompressedPicFiles │ 2 │ 0.19 │ 202319 │
├────────────────────────────┼───────┼──────────┼─────────────┤
│ cannotBeCompressedPicFiles │ 0 │ 0.00 │ 0 │
└────────────────────────────┴───────┴──────────┴─────────────┘
Notice: Gif and svg files cannot be compressed.
Total size(MB): 0.19MB
Total size(Bytes): 202319
? Please input a valid tinypng api key to continue ( You can find it at https://tinify.com/dashboard/api ):
```After entering the tinyPNG API Key, the compression will start automatically.
```
? Please input a valid tinypng api key to continue ( You can find it at https://tinify.com/dashboard/api ): YOUR_API_KEY_HERE
processing: 1 / 2 assets/continue.png
processing: 2 / 2 assets/logo.png
_____ _ _ _ _
| ___|(_) _ __ (_) ___ | |__ ___ __| |
| |_ | || '_ \ | |/ __|| '_ \ / _ \ / _` |
| _| | || | | || |\__ \| | | || __/| (_| |
|_| |_||_| |_||_||___/|_| |_| \___| \__,_|┌────────────────────────────┬───────┬──────────┬─────────────┐
│ │ Count │ Size(MB) │ Size(Bytes) │
├────────────────────────────┼───────┼──────────┼─────────────┤
│ canBeCompressedPicFiles │ 2 │ 0.06 │ 59916 │
├────────────────────────────┼───────┼──────────┼─────────────┤
│ cannotBeCompressedPicFiles │ 0 │ 0.00 │ 0 │
└────────────────────────────┴───────┴──────────┴─────────────┘
Notice: Gif and svg files cannot be compressed.
Total size(MB): 0.06MB
Total size(Bytes): 59916
================================================================================
The total size has decreased by 70.39% after compression.
```## Additional information
### What if it show an error while compressing?
Most of the time, it's because you have exceeded the monthly limit of tinyPNG. You can use another API Key to continue. Like below:
```
processing: 72 / 123 src/images/payWays/master.png
processing: 73 / 123 src/images/payWays/p30_promo_banner_en.png
The error message is: Your monthly limit has been exceeded. (HTTP 429/TooManyRequests)
? Please input a valid tinypng api key to continue ( You can find at https://tinify.com/dashboard/api ): YOUR_ANOTHER_API_KEY_HERE
processing: 73 / 123 src/images/payWays/p30_promo_banner_en.png
processing: 74 / 123 src/images/payWays/p30_promo_banner_zh.png
```## Contribution
If you have any questions or suggestions, please feel free to open an [issue](https://github.com/Gaohaoyang/compress-pics/issues) or [pull request](https://github.com/Gaohaoyang/compress-pics/pulls).
Enjoy it! :smile:
Have a nice day!