# compress_y

> compress image

Latest version **1.1.1** (published 2018-09-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install compress_y
pnpm add compress_y
yarn add compress_y
bun add compress_y
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2018-09-12 |
| First published | 2018-02-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 32.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | youngwong |
| Maintainers | youngwong |
| Keywords | compress image |

## Links

- npm: https://www.npmjs.com/package/compress_y
- npm.io page: https://npm.io/package/compress_y

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2018-09-12
- 1.1.0 — 2018-09-12
- 1.0.4 — 2018-02-01
- 1.0.3 — 2018-02-01

## README

#### 参数解释:
 - maxWidth: 允许的最大图片宽度(必填, number类型)
 - maxHeight: 允许的最大图片高度(必填, number类型)
 - selector: 图片预览的容器ID(不需此功能传空 '', string类型)
 - ifCut: 是否剪裁图片(默认取图片中心，剪裁成正方形, boolean类型)
 - cb: 回调函数(用于获取数据, function)，有两个参数：1.当前图片的base64值  2.多个图片的base64数组
 
#### 使用方法：
 - 1.引入
 - 2.创建Compress对象
 - 3.调用Compress对象的readImg方法(需传入event事件对象)
 - 4.通过回调函数获取base64值或数组，进行后续操作

 ```
 <!-- html -->
 <input type="file" accept="image/jpg,image/jpeg,image/png,image/gif" onchange="uploadImg(event)">
 
 <!-- 引入 -->
 var Compress = require('compress_y')
 or
 import Compress from 'compress_y'
 
 <!-- js -->
 function uploadImg (event) {
 	var compressObj = new Compress(300, 300, '', true, getBase64);
 	compressObj.readImg(event);
 }

 function get getBase64 (base64, base64Arr) {
 	// base64 string
 	// an array of base64 string
 }
 
 ```

 > 功能解释: 当上传图片尺寸大于参数maxWidth, maxHeight任意一项，则对图片进行等比缩放。暂无自定义剪裁功能

---
_Source: https://npm.io/package/compress_y · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
