javascript - 如何在节点 js 中使用 jimp 在多个图像上打印不同的文本?
问题描述
我想创建一张礼品卡来发送许多带有不同文本的电子邮件,我正在使用下面的逻辑来打印它的工作,但用生成的前一张图像覆盖。
Jimp.read(fileName)
.then(function (image) {
loadedImage1 = image;
return Jimp.loadFont(Jimp.FONT_SANS_16_BLACK);
})
.then(font => {
console.log('[][][', emailData);
var paths = [];
for(let i=0; i< Object.keys(emailData['recipient']).length; i++){
var receipentName = "Hello "+emailData['recipient'][i].name+', ';
loadedImages[i]= Object.assign(loadedImage1);
loadedImages[i].print(font, 220, 400, header, 500);
loadedImages[i].print(font, 220, 440, venue, 500);
loadedImages[i].print(font, 220, 460, location, 500);
loadedImages[i].print(font, 220, 520, receipentName, 500);
loadedImages[i].print(font, 220, 580, message, 500);
//loadedImage.print(font, 10, 30, imageCaption);
var path= basePath + '/invitation/' + bookingId + '/' + bookingId+i + '.jpg';
//let fullPath = config.BASE_URL + '/uploads/invitation/' + bookingId + '/' + bookingId+i + '.jpg';
paths[i] = path;
loadedImages[i].write(path);
}
res.status(200).json({
data: {
paths: paths,
path: path, //config.BASE_URL + '/uploads/invitation/' + bookingId + '/' + bookingId + '.jpg',
bookingData: detail,
restaurantDetails: restaurantDetails
},
status: 1,
msg: "Notes data"
});
})
.catch(function (err) {
console.error(err);
});
解决方案
代替
loadedImages[i]= Object.assign(loadedImage1);
采用
loadedImages[i]= loadedImage1.clone();
推荐阅读
- python - 在单个 GPU 上使用 Pytorch 并行化简单的 for 循环
- react-native - 关于如何处理 React Native + React Native Web Stack 的 EndToEnd 测试的建议?
- javascript - 如何从单独的域请求 JSON 数据并自己使用它
- php - 我在 php://input 函数上做错了什么?
- sql-server - 在 sql 中替代 except
- spring - 为什么我无法在构建 UI 后修改 vaadin 组件状态?
- android - 如何在 Android 中获取 Google 日历事件或系统添加的日历事件?
- php - 在副本上创建“消息”
- azure-devops - 如何在 Azure Dev Ops 中访问任务输出变量
- algorithm - 优化 2D 调色板排列的算法