当前位置:网站首页>JS image resolution compression

JS image resolution compression

2022-06-23 00:45:00 Ziwei front end

/** 
 * @desc   SVG turn PNG
 * @param  {Object} obj 
 * @param  {Number} obj.scale  The zoom 
 * @param  {Number} obj.length  length 
 * @param  {String} obj.src  Picture path 
 * @param  {Boolean} obj.base64  Output data type Yes No  base64
 * @param  {Function} obj.success  Successful callback 
 * @param  {Function} obj.error  Failed callback 
 */
function dealImage(obj) {
    var img = new Image();
    img.src = obj.src;
    img.onload = function () {
        //  Default scale compression 
        var w = this.width,
            h = this.height,
            scale = w / h;
        if (obj.length) {
            if (w > h) {
                w = obj.length;
                h = (w / scale);
            } else {
                h = obj.length;
                w = (h * scale);
            }
        } else {
            w = obj.width || w;
            h = obj.height || (w / scale);
        }
        // Generate canvas
        var canvas = document.createElement('c
原网站

版权声明
本文为[Ziwei front end]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206222049583246.html