const dw = require('digital-watermarking');
const fs = require('fs').promises;
//EnCode Image add digital watermarking
let enCodeFileName = "encode.jpg";
async function DigitalWaterTag(filePath,tag_text) {
let watermarkText = tag_text;
let fontSize = 2;
const img_buffer = await fs.readFile(filePath);
let image = await dw.transformImageBufferWithText(img_buffer,watermarkText,fontSize);
image.write(enCodeFileName, (err, image) => {
if (err) {
console.error('保存图像时出错:', err);
return;
}
console.log('图像保存成功!');
});
}
readImageAsBuffer()
// //DeCode Image get digital watermarking
// let deCodeFileName = "decode.jpg";
// dw.getTextFormImage(enCodeFileName,deCodeFileName);
// console.log("out")
数字水印,图像编码,图像解码,水印文本,图像处理
使用JavaScript代码为图像添加数字水印,通过digital-watermarking库实现图像编码和解码,保护图像版权。