<input type="file" accept="image/*" id="img-file"/>
$("#img-file").change(function() {
let reader = new FileReader();
//这里把一个文件用base64编码
reader.readAsDataURL($(this)[0].files[0]);
reader.onload = function(e){
let newImg = new Image();
//获取编码后的值,也可以用this.result获取
newImg.src = e.target.result;
newImg.onload = function () {
/* 获取 this.height tthis.width*/
var dataURL = compress(newImg,this.width,this.height,0.8);
/*为了兼容ios 需要 dataURL-> blob -> file */
var blob = dataURLtoBlob(dataURL); // dataURL-> blob
var file = blobToFile(blob, '999'