Skip to content

Sharp for Image Watermark Demo

How to Add text watermarks to protect your images using Sharp.

Usage

Add text watermarks to images using SVG overlay. Customize text, position, and opacity.

Parameters

  • text: Watermark text content
  • position: Position on the image (center, north, south, east, west, etc.)
  • opacity: Watermark transparency (0-1)

Example

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 MyBrand
    </text>
  </svg>
`);

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

Released under the Apache 2.0 License.