【发布时间】:2021-05-18 10:22:58
【问题描述】:
当我尝试使用 Canvas 在图片上显示文本时,某些字符和表情符号在 Windows 和 Ubuntu 上显示不正确。 1 个屏幕 - 在 Windows 上,2 个屏幕 - 在 Ubuntu 上。对于任何字体,情况都是如此。在 Windows 上画布,在 Ubuntu 上画布,我刚刚通过 npm install canvas 安装。
窗户
Ubuntu
代码:
const canvas = Canvas.createCanvas(1000,333)
const ctx = canvas.getContext('2d');
const background = await Canvas.loadImage('https://i.imgur.com/YzwG7yk.jpeg')
ctx.drawImage(background, 0, 0, canvas.width, canvas.height)
ctx.font = '300 30px "Arial"'
ctx.fillStyle = '#ffffff'
ctx.fillText(`????????????\nマークとニック\nP????????????z????k`, 70, 70)
const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'xp.png');
return message.channel.send(attachment)
【问题讨论】:
-
这段代码是什么?它不是在浏览器中运行的东西。
-
我认为您的问题与默认编码有关;你可以尝试用对应的unicode字符代码替换所有的chatacters(例如
????变成\u1f497) -
@mplungjan,我在 discord js 中使用它
-
@secan,没有帮助
标签: javascript canvas discord.js node-canvas