nodejs 图片增加数字水印

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")

作者:spike

分类: Nodejs

创作时间:2024-06-04

更新时间:2024-06-04

联系方式放在中括号之中例如[[email protected]],回复评论在开头加上标号例如:#1