Skip to content

水印演示

为图片添加文字水印以保护您的作品。

使用方法

使用 SVG 叠加为图片添加文字水印。可自定义文字、位置和透明度。

参数

  • text: 水印文字内容
  • position: 在图片上的位置(中心、顶部、底部、左侧、右侧等)
  • opacity: 水印透明度 (0-1)

示例

javascript
const svg = Buffer.from(`
  <svg width="800" height="600">
    <text x="50%" y="50%" text-anchor="middle" 
          style="fill: white; font-size: 48px; opacity: 0.5;">
      © 2026 我的品牌
    </text>
  </svg>
`);

await sharp('input.jpg')
  .composite([{ input: svg, gravity: 'southeast' }])
  .toFile('watermarked.jpg');

基于 Apache 2.0 许可证发布