我需要使用 Jimp 节点模块在图像上添加文本。但有时它会与图像混淆。例如:黑色文本悬停在本身带有黑色的图像上。
所以我需要插入一个白色方块并在里面写上黑色。
在 Jimp 的文档中没有找到它。
我的实际代码:
await Jimp2.read(nomeArquivo)
.then(function (image) {
loadedImage = image;
return Jimp2.loadFont(Jimp2.FONT_SANS_16_BLACK);
})
.then(function (font) {
loadedImage.print(font, 45, 45,'car' ,450 , (err, image, { x, y }) => {
image.print(font, 45, y + 4, {
text: 'this car is ok',
alignmentX: Jimp2.HORIZONTAL_ALIGN_CENTER,
alignmentY: Jimp2.VERTICAL_ALIGN_MIDDLE
},450);
} )
.write(nomeArquivo);
})
.catch(function (err) {
console.error(err);
});
这会将文本悬停在图像上,而不是正方形。
谢谢!