An open API service indexing awesome lists of open source software.

https://github.com/ghkmmm/shrinkpng

Compress the image files obtained by the front end
https://github.com/ghkmmm/shrinkpng

image-compression react tinypng typescript vuejs

Last synced: about 1 year ago
JSON representation

Compress the image files obtained by the front end

Awesome Lists containing this project

README

          

shrinkpng

Compress the image files obtained by the front end


💻 Official website  
🌍 Github  
🚀 Npm

使用[UPNG.js](https://github.com/photopea/UPNG.js)对 PNG 文件进行有损缩小,类似于[TinyPNG](https://tinypng.com/)和其他工具。

## 安装

打开终端运行下列命令:

```
npm install shrinkpng
```

```
yarn add shrinkpng
```

## 开始使用

请先[下载]()本插件

然后在你的代码中引入 shrinkpng

```js
import { shrinkImage } from "shrinkpng";

...
const _file = await shrinkImage(file, {
quality: 80
});
```

#### Vue 文件示例

代码示例

```vue



import { shrinkImage } from "shrinkpng";

export default {
name: "App",
mounted() {
document.getElementById("imgUpFile").addEventListener("change", (e) => {
const file = e.target.files[0];
const _file = await shrinkImage(file, {
quality: 80
}); // compress file
});
},
};

```