javascript - 我需要组合两个图像,以便它们在 discord.js 中并排在一起
问题描述
我想这样做,所以我的机器人将两个上传的图像组合成一个图像,上传的图像并排(水平)放置。我的程序提示用户上传第一张照片,然后上传第二张照片。收到照片后,我希望将它们组合起来。我尝试使用 Jimp 将照片合成到更大的裁剪照片上,但我无法让机器人发送合成结果。
// ------------------------------------------ front photo ------------------------------------------
message.channel.send({embed: {color: '#ffdf20', description: 'Upload front photo'}});
// waits for link message,
await message.channel.awaitMessages(filter, {
max: 1,
time: 60000,
errors: ['time']
})
.then(async(collected) => {
frontphoto = collected.first().attachments.first().url;
// ------------------------------------------ back photo ------------------------------------------
message.channel.send({embed: {color: '#ffdf20', description: 'Upload back photo'}});
// waits for link message,
await message.channel.awaitMessages(filter, {
max: 1,
time: 60000,
errors: ['time']
})
.then(async(collected) => {
backphoto = collected.first().attachments.first().url;
这是我尝试对 Jimp 执行的操作,但我的程序遇到内存泄漏并且无法发布照片。上传的两张照片的尺寸都是 h:4032 和 w:3024,所以最终的图像尺寸应该是 h:4032 和 w:6048。
let h, w;
let combined_photo;
Jimp.read(frontphoto).then(front => {
Jimp.read(backphoto).then(back => {
Jimp.read(<random image backgroun>).then(async(new_image) => {
h = front.bitmap.height;
w = (front.bitmap.width) * 2;
await new_image.resize(w,h);
console.log(new_image.bitmap.height);
console.log(new_image.bitmap.width);
await new_image.composite(front,0,0);
await new_image.comspostie(back,w/2,0);
combined_photo = new_image;
});
});
});
解决方案
推荐阅读
- javascript - 找不到角度服务工作者 ngsw_serviceworker.es6.js.map
- go - 如何使用 gopkg 安装 ginkgo 和 gomega?
- ruby-on-rails - 如何使用 Active Storage 从 URL 存储图像
- c - 编译旧的 C 代码 + X86 分解它
- sql - 如何将数据插入具有引用和范围的表中
- c# - Xamarin iOS 等效于 ApplicationData.Current.LocalFolder
- scala - 当我尝试在项目中添加节点模块时,sbt 无法运行
- sql - SQL Server - 将 SELECT 语句存储到存储过程中的变量中
- mysql - MySQL - 尝试将 `GROUP_CONCAT` 与 `COUNT()` 结合使用
- inno-setup - Inno Setup:未知标识符“IsWin64”