@muyi086/img-compress
v1.0.10
Published
img compress
Downloads
3
Readme
img-compress
Install
npm install @muyi086/img-compress
# common JS
const { imgCompress } = require('@muyi086/img-compress')
# es6
import { imgCompress } from '@muyi086/img-compress'
Use
Currently only supports pc, mobile framework uniapp and others will hijack canvas related functions, causing unable to create the native canvas of the browser.
// Data loaded without CORS approval will cause the canvas to be polluted, and the canvas.toDataURL will report an error
// compress img, return base64
console.log(imgCompress.compress(imgObj, quality))
// download compressed img
console.log(imgCompress.downloadImg(imgObj, name, quality))
Function
function|parameter|default|required|description| --|--|--|--|--| compress|object||required|a img object| compress|number|1|optional|a float between 0 and 1| downloadImg|object||required|a img object| downloadImg|string||required|name for save new img| downloadImg|number|1|optional|a float between 0 and 1|
Tips
A Number between 0
and 1
indicating the image quality to use for image formats that use lossy compression such as image/jpeg
and image/webp
.