1 回答
TA贡献1862条经验 获得超7个赞
您可以为此使用 Jimp。这是 NPM 网站:https ://www.npmjs.com/package/jimp
它允许您修改图片、添加文本等。您想要的内容类似于以下内容:
//an array of all images we're using. MAKE SURE THEIR SIZES MATCH
var images = [<link to the user's avatar>, <link to an image of jail bars>]
var jimps = []
//turns the images into readable variables for jimp, then pushes them into a new array
for (var i = 0; i < images.length; i++){
jimps.push(jimp.read(images[i]))
}
//creates a promise to handle the jimps
await Promise.all(jimps).then(function(data) {
return Promise.all(jimps)
}).then(async function(data){
// --- THIS IS WHERE YOU MODIFY THE IMAGES --- \\
data[0].composite(data[1], 0, 0) //adds the second specified image (the jail bars) on top of the first specified image (the avatar). "0, 0" define where the second image is placed, originating from the top left corner
//you CAN resize the second image to fit the first one like this, if necessary. The "100, 100" is the new size in pixels.
//data[1].resize(100,100)
//this saves our modified image
data[0].write(<path on your local disk to save the image in>)
})
现在您所要做的就是从本地磁盘发送图像:
message.channel.send(`Jailed!`, {file: `${<path to the image>}`})
添加回答
举报