SOURCE

			//path 图片地址
			//let prop = parseInt(Math.sqrt(图片地址.length / 102400 / 1.3));
			//使用canvas压缩图片
			compressedImg = function(path, prop) {
				let img = new Image();
				img.src = path;
				img.onload = function() {
					let that = this;
					// 按压缩比例进行压缩
					let w = that.width / prop;
					let h = that.height / prop;
					let quality = 1; // 默认图片质量为1
					let canvas = document.createElement('canvas');
					let ctx = canvas.getContext('2d');
					//创建属性节点
					let anw = document.createAttribute("width");
					anw.nodeValue = w;
					let anh = document.createAttribute("height");
					anh.nodeValue = h;
					canvas.setAttributeNode(anw);
					canvas.setAttributeNode(anh);
					//context.drawImage(img,x,y,width,height);
					ctx.drawImage(that, 0, 0, w, h);//zua  e men ju
					// quality值越小,所绘制出的图像越模糊
					var imgUrl = canvas.toDataURL('image/jpeg', quality); //压缩后的图片base64码
				}
			}
console 命令行工具 X clear

                    
>
console