2 回答

TA貢獻1841條經驗 獲得超3個贊
基本上,Canvas 是一種圖像處理工具,可讓您使用代碼修改圖像。因此,為了調整圖像大小,您需要從本地目錄上傳它。
const canvas = Canvas.createCanvas(700, 250);
const ctx = canvas.getContext('2d');
const background = await Canvas.loadImage('./wallpaper.jpg')
// This uses the canvas dimensions to stretch the image onto the entire canvas
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);

TA貢獻1853條經驗 獲得超6個贊
您可以使用Sharp調整圖像大小,然后將其作為附件添加到嵌入中。不過,您仍然需要獲取圖像才能執行此操作。
假設您已經將圖像(您可以從外部源獲取或在本地加載)作為Buffer
名為 的變量image
,您的代碼將如下所示:
const sharp = require('sharp')
sharp(image).resize({ width: 100, height: 100 }).toBuffer().then(resizedImage => {
const attachment = new Discord.MessageAttachment(resizedImage, 'image.png');
const embed = new Discord.MessageEmbed()
.setTitle('This embed has a resized image attached to it!')
.attachFiles(attachment)
.setImage('attachment://image.png')
channel.send(embed)
})
您可以在此處閱讀有關使用銳利調整圖像大小的更多信息。
添加回答
舉報