画布拉伸图像

时间:2020-03-11 20:40:00

标签: node.js canvas discord.js

我刚刚在Discord bot上完成了等级系统,但是有人用低分辨率的个人资料图片运行了该命令,并且代码似乎无法拉伸图像以适应要求,怎么办?另外,当我在这里时,也许您可​​以看看我的弧形?我对画布不是很满意,而且您在图像中看到的黑色边框并不是一路均匀,我该如何改变它以从中心围绕照片创建圆弧? 代码:

    ctx.beginPath();
    ctx.arc(122.5, 141.8, 81, 0, Math.PI * 2, true);
    ctx.strokeStyle = '#000000';
    ctx.lineWidth = 6;
    ctx.stroke();
    ctx.save();
    ctx.closePath();
    ctx.clip();
    const avatar = await Canvas.loadImage(
      message.author.displayAvatarURL({ format: 'png' }),
    );
    ctx.strokeStyle = '#ffffff';
    ctx.strokeRect(0, 0, canvas.width, canvas.height);
    ctx.drawImage(avatar, 41.5, 60.5, 162, 162);

我的PFP输出:enter image description here 较低的分辨率输出:enter image description here

0 个答案:

没有答案