zoukankan      html  css  js  c++  java
  • 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); 
        }; 
       }    
    

      

  • 相关阅读:
    三个习题
    20 python--celery
    19 python --队列
    18 python --多线程
    17 python --多进程
    16 python --memcached
    15 python --redis
    14 python --mysql
    13 python --正则
    12 python --json
  • 原文地址:https://www.cnblogs.com/peter-web/p/10710531.html
Copyright © 2011-2022 走看看