1.0.10 • Published 1 year ago

@muyi086/img-compress v1.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

img-compress

中文

npm npm bundle size npm GitHub

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

functionparameterdefaultrequireddescription
compressobjectrequireda img object
compressnumber1optionala float between 0 and 1
downloadImgobjectrequireda img object
downloadImgstringrequiredname for save new img
downloadImgnumber1optionala 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 .

Wiki

  1. HTMLCanvasElement.toDataURL()
1.0.10

1 year ago

1.0.9

1 year ago

1.0.2

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago