这个东东的github是https://github.com/think2011/localResizeIMG
按照说明和demo演示http://think2011.github.io/localResizeIMG/test/
写了如下代码,但是不能正常预览:
1、引入js
<script src="/js/dist/lrz.bundle.js"></script>
2、view
<div id="upload-container" class="col-xs-12 text-center">
<input onchange="upload().bind(this)" type="file" accept="image/*" />
</div>
3、script
function upload () {
lrz(this.files[0])
.then(function (rst) {
var img = new Image(),
div = document.createElement('div'),
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 = '源文件:<span class="text-danger">' +
sourceSize + 'KB' +
'</span> <br />' +
'压缩后传输大小:<span class="text-success">' +
resultSize + 'KB (省' + scale + '%)' +
'</span> ';
div.className = 'col-sm-6';
div.appendChild(img);
div.appendChild(p);
img.onload = function () {
document.querySelector('#upload-container').appendChild(div);
};
img.src = rst.base64;
return rst;
})
.catch(function (err) {
alert(err);
})
.always(function () {
});
}
另外:前端压缩图片,大家一般用什么插件?