您好,我尝试使用 gm 和 jimp 模块在 discord.js 上缓冲相同的图像 jimp 用于添加 img(用户头像)和 gm 用于添加文本(用户用户名)但我失败了,因为我找不到让 gm 识别的方法jimp 的缓冲结果并再次编辑并发送它我在下面尝试了这段代码
const Discord = require("discord.js");
const Jimp = require("jimp");
const gm = require('gm').subClass({imageMagick: true})
module.exports.run = async (bot, message, args) =>
{
let GuildMember = message.mentions.members.first();
if(!GuildMember)
{
return await message.reply(" must mention someone!");
}
message.channel.startTyping();
var GetUserAvatar = (GuildMember.user.avatarURL === null) ? GuildMember.user.defaultAvatarURL : GuildMember.user.avatarURL;
var i1 = Jimp.read(GetUserAvatar);
var i2 = Jimp.read("./images/why.jpeg");
var FontSize = (GuildMember.user.username.length >= 20) ? 14 : 20;
Promise.all([i1, i2]).then(async images =>
{
await images[0].scaleToFit(120, 120).quality(100);
await images[1].composite(images[0], 30, 140).quality(100).getBuffer(Jimp.MIME_PNG, async (err, buffer) =>
{
if(err)
{
return console.log("error ==>> " + err).then(()=> message.channel.stopTyping(true)).catch(err => message.channel.stopTyping(true));
}
});
});
var images = images;
await gm(images)
.font("Helvetica.ttf", FontSize)
.fill("#111111")
.stroke("#800000")
.draw(["rotate -55 text -430, 480 '" + GuildMember.user.username.trim() + "'"])
.toBuffer(images, async function (err, buffer)
{
if(err)
{
return console.log("error ==>> " + err).then(()=> message.channel.stopTyping(true)).catch(err => message.channel.stopTyping(true));
}
await message.channel.send(new Discord.Attachment(buffer, images)).then(()=> message.channel.stopTyping(true)).catch(err => message.channel.stopTyping(true));
});
};
module.exports.help =
{
name: "what"
};