picture-compressor-plus
Version:
前端图片压缩工具,使用 canvas 对图片做压缩处理。
38 lines (36 loc) • 1.04 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>测试</title>
</head>
<body>
<input type="file" id="file" />
<script src="../dist/picture-compressor-plus.js"></script>
<script>
rotate = 0;
let files = document.getElementById('file');
files.addEventListener('change', () => {
let file = files.files[0];
let reads = new FileReader();
reads.readAsDataURL(file);
reads.onload = function() {
console.log(this);
pictureCompress({
img: this.result,
width: 1200,
height: 0,
rotate: rotate,
}).then(res => {
console.log(res.width, res.height);
var img = new Image();
img.src = res.img;
document.body.appendChild(img);
});
};
});
</script>
</body>
</html>