canvas绘制圆图输出图片格式

  
         function drawCircleImage(url, callback) {
            const canvas = document.createElement('canvas');
            const img = new Image();
            img.setAttribute("crossOrigin", 'Anonymous');
            img.src = url;
            img.onload = function() {
                canvas.width = img.width;
                canvas.height = img.height;
                let ctx = canvas.getContext("2d");
                //获取图片宽高的最小值
                let min = Math.min(img.width, img.height);
                let r = min / 2;
                ctx.fillStyle = ctx.createPattern(img, 'no-repeat');
                ctx.clearRect(0, 0, img.width, img.height);
                ctx.arc(img.width / 2, img.height / 2, r, 0, Math.PI * 2);
                ctx.fill();
       let base64 = canvas.toDataURL("image/jpeg");
       callback(base64); 
    }; 
   }    

  

原文地址:https://www.cnblogs.com/peter-web/p/10710531.html