这个东东的github是https://github.com/think2011/localResizeIMG
按照说明和demo演示http://think2011.github.io/localResizeIMG/test/
写了如下代码,但是不能正常预览:
1、引入js
2、view
3、script
function upload () {
lrz(this.files[0])
.then(function (rst) {
var img = new Image(),
p = document.createElement('p'),
p = document.createElement('p'),
sourceSize = toFixed2(that.files[0].size / 1024),
resultSize = toFixed2(rst.fileLen / 1024),
scale = parseInt(100 - (resultSize / sourceSize * 100));
p.style.fontSize = 13 + 'px';
p.innerHTML = '源文件:' +
sourceSize + 'KB' +
'
' +
'压缩后传输大小:' +
resultSize + 'KB (省' + scale + '%)' +
' ';
p.className = 'col-sm-6';
p.appendChild(img);
p.appendChild(p);
img.onload = function () {
document.querySelector('#upload-container').appendChild(p);
};
img.src = rst.base64;
return rst;
})
.catch(function (err) {
alert(err);
})
.always(function () {
});
}
另外:前端压缩图片,大家一般用什么插件?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
学习是最好的投资!