
[中文](./README.md) |-> [English](./README.en.md)


### 🍴 Fork

This is a fork of the  [picgo-plugin-compress-webp-lossless](https://github.com/mrgeneralgoo/picgo-plugin-compress-webp-lossless) repository, And it is a fork of the [picgo-plugin-compress](https://github.com/JuZiSang/picgo-plugin-compress) repository.


### 🚀 Deployment and Use

#### [PicGo-Core](https://github.com/PicGo/PicGo-Core) Install

- Install `picgo add compress-next`.
- Choose to use `picgo use transformer`.
- Configuration `picgo config plugin compress-next`.


#### [PicGo-Gui](https://github.com/Molunerfinn/PicGo) Install

- Open the details window > Plug-in Settings > Search for `compress-next` to install, click on the lower right corner of the module to configure.
- or, go to the 'picgo' directory 'npm i picgo-plugin-compress-next'.
- Offline installation Reference [here](https://picgo.github.io/PicGo-Core-Doc/zh/dev-guide/deploy.html#gui%E6%8F%92%E4%BB%B6).


#### Configuration
- Compress Type (A detailed comparative analysis table will be made later):
  - [tinypng](https://tinypng.com/): Damaged compression, need to upload to tinypng.
  - [imagemin](https://github.com/imagemin/imagemin): Image compression does not change the suffix, support `jpeg` and `png`. Use [mozjpeg](https://www.npmjs.com/package/imagemin-mozjpeg) and [upng](https://www.npmjs.com/package/imagemin-upng).
  - [imagemin-webp](https://www.npmjs.com/package/imagemin-webp): Local compression to webp.
  Note: Some beds (such as sm.ms) do not support webp image format and will fail to upload.
  - [webp-converter](https://www.npmjs.com/package/webp-converter): Same as the last one.
- Gif Compress Type:
  - [webp-converter](https://www.npmjs.com/package/webp-converter): Local lossy compresses gif to webp.
  - [imagemin-gif2webp](https://www.npmjs.com/package/imagemin-gif2webp): 
- Auto Refresh TinyPng Key Across Months:
  - yes: The TinyPng API Key status is automatically refreshed if it is detected to be across months (different from the last time it was used).
  - no: No detection, but still record the date.
- TinyPng API Key:
  - Apply in [developers](https://tinypng.com/developers).
  - Separated by comma(`,`), multiple keys can be used to superimpose the usage times.


##### Compression parameter configuration

Go to see [option.example.json](./docs/option.example.json)



# ⚗️ Background

The [picgo-plugin-compress](https://github.com/JuZiSang/picgo-plugin-compress) has been a long time not updated, The key is in ` PicGo ` underlying upload library from ` request ` migrated to ` axios `, reference [PicGo/PicGo-Core#65](https://github.com/PicGo/PicGo-Core/issues/65), led to [TinyPng](https://tinypng.com/) is unavailable. Seems to be the last available version is [PicGo v2.3.0](https://github.com/Molunerfinn/PicGo/releases/tag/v2.3.0).  

Fortunately I found the [picgo-plugin-compress-webp-lossless](https://github.com/mrgeneralgoo/picgo-plugin-compress-webp-lossless), But its only upload [v1.0.1](https://www.npmjs.com/package/picgo-plugin-compress-webp-lossless). Its implementation is still through older versions of the [picgo-plugin-compress](https://github.com/JuZiSang/picgo-plugin-compress). However, the code updates the ` v1.1.0 `, but after refactoring with 'ES' it is not compatible with 'PicGo', and there are still some problems.

So there is ***`picgo-plugin-compress-next`*** birth 🎉

# 💥 Comparison

<table border=2 style="
  width: auto;
  display: table;
  margin-left: auto;
  margin-right: auto;"
>
  <tr>
    <th></th>
    <th colspan=2>compress-next</th>
    <th colspan=2>compress</th>
  </tr>
  <tr>
    <th rowspan=5>TinyPng</th>
    <td>✅</td>
    <td>version >= <b>2.3.1</b></td>
    <td>🟡</td>
    <td>Highest version <b>2.3.0</b></td>
  </tr>
  <tr>
    <td>✅</td>
    <td>
      Multiple keys are used in combination<br>
      Use commas to separate and automatically clear whitespace
    </td>
    <td>✅</td>
    <td>
      Multiple keys are used in combination<br>
      Strictly use commas, no whitespace
    </td>
  </tr>
  <tr>
    <td>✅</td>
    <td>
      TinyPngWeb is deprecated<br>
      Throws an exception and prompts you to configure the Key
    </td>
    <td>❌</td>
    <td>
      TinyPngWeb is unavailable<br>
      Throwing a blank exception can only view logs<br>
      Page returns <b>404</b> or <b>413</b>
    </td>
  </tr>
  <tr>
    <td>✅</td>
    <td>
      <b>automatically skips</b> when an invalid Key appears<br>
      Tags are no longer accessed unless manually refreshed
      </td>
    <td>❌</td>
    <td>
      An invalid Key occurs, throwing a blank exception<br>
      View log, page return <b>404</b>
    </td>
  </tr>
  <tr>
    <td>✅</td>
    <td>
      Supports manual refreshing of <b>Valid</b> Keys<br>
      Supports manual refreshing of <b>all</b> Keys<br>
      Can be set to <b>automatically</b> refresh Key if across months
    </td>
    <td>❌</td>
    <td>
      If the valid Key reaches the number of times, the access is stopped<br>
      The configuration file can be reset only after it is deleted
    </td>
  </tr>
  <tr>
    <th rowspan=4>imagemin</th>
    <td>✅</td>
    <td>
      <b>mozjpeg</b> & <b>upng</b>:<br>
      Can configure compression parameters
    </td>
    <td>🟡</td>
    <td>
      <b>mozjpeg</b> & <b>upng</b>:<br>
      Support for local lossy conversion
    </td>
  </tr>
  <tr>
    <td>✅</td>
    <td>
      <b>imagemin-webp</b>:<br>
      Can configure compression parameters
    </td>
    <td>🟡</td>
    <td>
      <b>imagemin-webp</b>:<br>
      Supports local lossy conversion to <b>webp</b>
    </td>
  </tr>
  <tr>
    <td>✅</td>
    <td>
      <b>imagemin-gif2webp</b>:<br>
      Supports <b>gif</b> local lossy conversion to <b>webp</b>
    </td>
    <td>❌</td>
    <td>Conversion from gif to webp is not supported</td>
  </tr>
  <tr>
    <td>✅</td>
    <td>Multiple sets of compression configuration parameters are prepared, and you can configure them yourself</td>
    <td>❌</td>
    <td>Fixed preset parameters</td>
  </tr>
  <tr>
    <th rowspan=2>webp-converter</th>
    <td>✅</td>
    <td>jpeg, png, webp compressed to webp</td>
    <td rowspan=2>❌</td>
    <td rowspan=2>Cannot use webp-converter</td>
  </tr>
  <tr>
    <td>✅</td>
    <td>Support gif compression to webp</td>
  </tr>
  <!-- <tr>
    <td>✅</td>
    <td></td>
    <td>❌</td>
    <td></td>
  </tr> -->
</table>


# 🎉 Function

- [x] Multiple keys can be used in combination
- [x] supports TinyPng compression for `PicGo >= v2.3.1`
- [x] disables `TinyPngWeb` and throws an exception
- [x] Handle error `Key` and skip
- [x] Handling refresh of `Key`
  - [x] Refreshing of `valid keys`
  - [x] Refreshing of `all keys`
  - [x] `Automatically` refresh `valid keys` if across months
- [x] add `webp-converter` (Smaller volume and Higher speed)
- [x] Add ability of `gift 2 webp`
  - [x] Use `webp-converter`'s `gwebp`
  - [x] `imagemin-gif2webp`
- [x] Can set compression parameters based on your requirements
  - [x] `imagemin-upng`
  - [x] `imagemin-mozjpeg`
  - [x] `imagemin-webp`
  - [x] `imagemin-gif2webp`
  - [x] `webp-converter-cwebp`
  - [x] `webp-converter-gwebp`


# Reporting Issues  

[You can click here directly to create an issue](https://github.com/supine0703/picgo-plugin-compress-next/issues/new)

