0

我想创建一张礼品卡来发送许多带有不同文本的电子邮件,我正在使用下面的逻辑来打印它的工作,但用生成的前一张图像覆盖。

            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);
            });
4

2 回答 2

2

代替

loadedImages[i]= Object.assign(loadedImage1);

采用

loadedImages[i]= loadedImage1.clone();
于 2020-02-17T09:36:11.377 回答
1

Object.assign 的正确语法是:

Object.assign(target, ...sources)

在您的情况下,正确的用法是:

loadedImages[i]= Object.assign({}, loadedImage1);
于 2020-02-17T09:43:20.617 回答