SOURCE

function compress(img) {
    var canvas = document.createElement("canvas");
    var ctx = canvas.getContext("2d");
    var width = img.width;
    var height = img.height;
    canvas.width = width;
    canvas.height = height;
    ctx.drawImage(img, 0, 0, width, height);
    var type = "image/jpeg";
    var img64 = canvas.toDataURL(type, 0.3);
    return img64;
}
console 命令行工具 X clear

                    
>
console