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>}`})
添加回答
舉報