Front-end Image Compression Tool.
You can use any package manager you like to import asshuku.
npm install asshuku
// or
yarn add asshuku
import { asshukuImage } from "asshuku";
... // other codes
const _file = await asshukuImage(file, {
quality : 50,
multAsshukuOptions : {
targetSize: 500 * 1024, // 500KB
maxRetryNum: 5, // total compress 6 times
qualityChangeFn : (quality) => quality / 3
}
});
Property | Description | Type | Default | Required |
---|---|---|---|---|
file | Image file witch you want to compress | File | true | |
asshukuOptions | options | AsshukuOptions | - | false |
Property | Description | Type | Default | Required |
---|---|---|---|---|
quality | compress quality (0 ~ 100) | Number | 80 | true |
multAsshukuOptions | options | MultAsshukuOptions | - | false |
Property | Description | Type | Default | Required |
---|---|---|---|---|
targetSize | Compressed target image size. | Number | - | true |
maxRetryNum | The maximum number of retries when the image is too large to compress to your target size | Number | - | true |
qualityChangeFn | How to reduce quality. Quality will not be reduced to negative numbers. (It means the minimum quality is 0) | Function | (quality) => quality / 2 | false |
Only supports ES2015 or newer versions.
- 🪧 source code
- 💻 npm