亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 discord.js 中為 discord bot 合并圖像?

如何在 discord.js 中為 discord bot 合并圖像?

小唯快跑啊 2022-06-05 16:39:59
我正在嘗試創建一個將頭像與圖像合并的命令,例如,如果有人鍵入 =jail,則頭像上的監獄欄 - 我已經創建了一個對命令進行排序的命令處理程序。但是,我無法弄清楚如何實現這一目標。我正在使用 Windows 平臺(顯然這意味著我不能使用節點 gd)
查看完整描述

1 回答

?
牧羊人nacy

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>}`})


查看完整回答
反對 回復 2022-06-05
  • 1 回答
  • 0 關注
  • 121 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號