mhbseal / html5imgcompress Goto Github PK
View Code? Open in Web Editor NEWhtml5图片压缩,支持pc,mobile(ios/android)和multiple
html5图片压缩,支持pc,mobile(ios/android)和multiple
下面done回调中的alert会执行2次
new html5ImgCompress(files[i], {
before: function(file) {
if(file.type.indexOf('image') == -1){
console.error("请选择图片进行上传");
return false;
}
// 这里一般是对file进行filter,例如用file.type.indexOf('image') > -1来检验是否是图片
// 如果为非图片,则return false放弃压缩(不执行后续done、fail、complete),并相应提示
},
done: function (base64, file) {
alert(11)
console.log('压缩成功...');
},
fail: function(file) {
console.log('压缩失败...');
},
complete: function(file) {
console.log('压缩完成...');
},
notSupport: function(file) {
console.log('浏览器不支持!');
// 不支持操作,例如PC在这里可以采用swfupload上传
}
});
代码:
var html5ImgCompress = require('/dist/html5ImgCompress.min.js');
错误信息:
TypeError: Cannot set property 'html5ImgCompress' of undefined
at index.js:506
at Module.<anonymous> (index.js:507)
at Module../assets/js/upload_img/html5ImgCompress.min.js (index.js:666)
at __webpack_require__ (runtime.js:788)
at fn (runtime.js:151)
建议搞一个npm安装包来引入,这样方便一些。
请问大大,现在是否是支持 png 图片压缩呢?
png with transparent background totally dark out.
fileChange(el){`
let that = this
for(let i = 0; i < el.target.files.length;i++){
// that.gallery.push(el.target.files[i])
new html5ImgCompress(el.target.files[i], {
before: function(file) {
console.log('压缩前...');
// console.log(typeof that.gallery)
// 这里一般是对file进行filter,例如用file.type.indexOf('image') > -1来检验是否是图片
// 如果为非图片,则return false放弃压缩(不执行后续done、fail、complete),并相应提示
},
done: function(file, base64) {
console.log('压缩成功...');
console.log(typeof that.gallery);
// ajax和服务器通信上传base64图片等操作
that.gallery.push(file)
},
fail: function(file) {
console.log('压缩失败...');
},
complete: function(file) {
console.log('压缩完成...');
},
notSupport: function(file) {
console.log('浏览器不支持!')
// 不支持操作,例如PC在这里可以采用swfupload上传
}
},false)
}
}
和vue一起使用,在chrome浏览器环境下。
这是我的监听input的代码,无法进入到done中,也不会跳转到notSupport,只是执行before之后就报错:
Uncaught SyntaxError: Unexpected token <
可否增加拍照与现成图像的选项功能
非常有用的工具,期待能以npm包的形式供大家引用。
大神!我很像学习下这个库怎么做到的,所以希望有没有压缩,不是打包给webpack的文件,但是我不会剥离
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.