'use strict';
import EXIF from 'exif-js';
class ImageCompressor {
constructor (options) {
this.defaultOpptions = Object.freeze({
file: null,
quality: 0.8,
type: 'image/jpeg',
scaleSize: 0,
pngMaxSize: 2097152,
width: 0,
height: 0
});
options = Object.assign({
}, this.defaultOpptions, options);
this.options = options;
this.file = this.options.file;
this.options.type = this.file.type;
this.image = null;
this.compress();
}
isFunction (data) {
return Object.prototype.toString.call(data).match(/\s(\w*)\]$/)[1] === 'Function';
}
imageTypeToExtension (type) {
let extension = type.substring(6);
extension === 'jpeg' && (extension = 'jpg');
return `.${
extension}`;
}
compress () {
this.fileToImage(this.file, image => {
this.isFunction(this.options.beforeCompress) && this.options.beforeCompress(this.file);
this.image = image;
!this
前端JS压缩图片
最新推荐文章于 2023-07-05 16:31:10 发布