有这样的数组:
var myArray=[
{ title: 'Some title', time: 'Some time'},
...
];
和node-gm代码:
gm('bg.png')
.fill("#ffffff")
.font("Phenomena-Bold.otf", 27)
.drawText(225, 75, "Some text")
.write("result.png", function (err) {
if (!err) console.log('done');
});
需要将myArray中的每个项目添加到.drawText(),并将y轴移动到45px。 有什么想法吗?
答案 0 :(得分:0)
你问过,我写过并测试过它。
采取(:
const
gm = require('gm');
const myArray = [
{ title: 'Some title', time: 'Some time'},
{ title: 'Second title', time: 'second time'}
];
const
image = gm('bg.jpg')
.fill('#ffffff')
.font('Arial', 27) // I didn't wanted to play with fonts, so used normal default thing (:
.drawText(225, 75, "Some text");
let x = 225;
let y = 75;
for(const text of myArray) {
y += 45;
image.drawText(x, y, text.title);
}
image.write('result.png', err => {
if(err) return console.error(err);
console.log('done');
});