如何在节点 js 中使用 jimp 在多个图像上打印不同的文本?
How to print different text on more than one image using jimp in node js?
我想创建一张礼品卡来发送多封不同文本的电子邮件,我使用以下逻辑来打印它的工作,但会覆盖之前生成的一张图片。
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();
Object.assign 的正确语法是:
Object.assign(target, ...sources)
在您的情况下,正确的用法是:
loadedImages[i]= Object.assign({}, loadedImage1);
我想创建一张礼品卡来发送多封不同文本的电子邮件,我使用以下逻辑来打印它的工作,但会覆盖之前生成的一张图片。
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();
Object.assign 的正确语法是:
Object.assign(target, ...sources)
在您的情况下,正确的用法是:
loadedImages[i]= Object.assign({}, loadedImage1);