A simple function using canvas to compress image file.
Usage
using cdn
using npm or yarn
- yarn:
yarn add frontend-image-compress
- npm:
npm i frontend-image-compress
const $file = document;$file { const file = etargetfiles0; const compressedFile = await }
API
when using script tag, you need to use window.Compress.xx
, Compress
is just a namespace
compressImageFile(file, quality):newFile
name | type | description |
---|---|---|
file | File | from input[type="file"] |
quality | number | range: 0~1, default is 0.7(decrease this value if you got console warning) |
return | Promise<File> | compressed file |
Changelog
-
2020-4-26
3.0.1
:- [breaking] filename changed when using cdn (from
frontend-image-compress.min.js
toindex.min.js
)
- [breaking] filename changed when using cdn (from
-
2019-03-16
3.0.0
:
- [breaking] add namespace to methods
- support
commonjs