【问题标题】:The blur filter doesn't work on discord.js [duplicate]模糊过滤器不适用于 discord.js [重复]
【发布时间】:2021-06-18 13:37:45
【问题描述】:

我最近遇到了“Canva”node.js 模块中的模糊过滤器问题。

它只是不起作用,没有错误或其他任何东西

    const canvas = Canvas.createCanvas(560, 315);

    const ctx = canvas.getContext('2d');

    const background = await Canvas.loadImage('./wallpaper.jpg');
    ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
    ctx.strokeStyle = '#74037b';
    ctx.strokeRect(0, 0, canvas.width, canvas.height);
    const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png');
    ctx.filter = "blur(500)"

问题已经打补丁了

【问题讨论】:

  • 看起来 node-canvas 还不支持过滤器 API。有关更多信息,请参阅this 问题。
  • 我建议使用 API 进行图像处理,如果您有兴趣,我实际上自己编写了一个,用于图像处理,它会制作模因和模糊图像等.....

标签: javascript node.js canvas discord.js blur


【解决方案1】:

确保在创建缓冲区对象之前应用filter

ctx.strokeRect(0, 0, canvas.width, canvas.height);
ctx.filter = 'blur(500)';
const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png');

【讨论】:

  • 我试过但还是不行
猜你喜欢
  • 1970-01-01
  • 2016-06-14
  • 1970-01-01
  • 1970-01-01
  • 2013-03-26
  • 1970-01-01
  • 2017-10-11
  • 1970-01-01
  • 2022-11-10
相关资源
最近更新 更多