标签:tee path 路径 new context 质量 nload 节点 base
function dealImage(path, callback){ var img = new Image(); img.src = path; img.onload = function(){ //默认按比例压缩 var w = this.width, h = this.height; var quality = 0.95; // 默认图片质量为0.7 //生成canvas var canvas = document.createElement(‘canvas‘); var ctx = canvas.getContext(‘2d‘); // 创建属性节点 canvas.setAttribute("width", w); canvas.setAttribute("height", h); ctx.drawImage(this, 0, 0, w, h); // quality值越小,所绘制出的图像越模糊 var base64 = canvas.toDataURL(‘image/jpeg‘, quality); // 回调函数返回base64的值 callback(base64); }; };
标签:tee path 路径 new context 质量 nload 节点 base
原文地址:https://www.cnblogs.com/jjmirai/p/9571240.html