DEV Community

Cover image for How Image Watermarking Works: Text, Logo, Steganography, and PDF Overlays
GeoImageTagger
GeoImageTagger

Posted on Originally published at geoimagetagger.com

How Image Watermarking Works: Text, Logo, Steganography, and PDF Overlays

Watermarking sounds simple — draw text on an image, export. But the implementation details vary significantly depending on the watermark type, the output format, and whether you need the watermark to survive lossy compression.

This article covers the technical side of five watermark types, the tradeoffs involved in each, and how modern browser-based tools handle them entirely client-side.

Canvas Compositing for Visible Watermarks

At the core, visible watermarking is a canvas compositing operation. The source image is drawn onto an HTML <canvas> element, then watermark layers are composited on top before the final pixel data is exported.

For text watermarks, the CanvasRenderingContext2D API provides fillText() and strokeText() with full control over font, color, opacity (globalAlpha), rotation (rotate()), and position (translate()). Effects like gradient fills use createLinearGradient(), and shadow is handled via shadowColor, shadowBlur, and shadowOffsetX/Y.

For logo watermarks, the uploaded logo image is drawn with drawImage() at the desired scale and position, with globalAlpha controlling transparency.

Tiled watermarks use a loop that repeats the drawImage() or fillText() call across a grid, calculating positions based on image dimensions, spacing, and rotation angle.

The entire operation runs in-browser using the Canvas API — no server round-trip is required.

Signature Capture with Pointer Events

Signature watermarks use a drawing canvas that captures pointer input. The pointerdown, pointermove, and pointerup events track stroke paths. Pressure-sensitive input is available via event.pressure on devices that support it, allowing variable stroke width.

The captured strokes are stored as path data, rendered onto a transparent canvas, and then composited onto the image like any other watermark layer.

LSB Steganography for Hidden Watermarks

Hidden watermarks use least-significant-bit (LSB) steganography. The concept: each pixel's color channels are represented as 8-bit integers (0–255). Changing the least significant bit of a channel shifts the value by at most 1 — a difference imperceptible to the human eye.

One common LSB approach works as follows:

  1. Convert the payload text to a binary bitstream (UTF-8 → bits).
  2. Optionally prepend a header for identification and a checksum for integrity verification.
  3. Iterate through image pixels, writing one payload bit into the LSB of a chosen color channel per pixel.
  4. Export as PNG (lossless) to preserve the encoded bits.

The critical constraint: LSB steganography requires lossless format preservation. JPEG and WebP use lossy compression algorithms (DCT-based and predictive, respectively) that alter pixel values during encoding. This destroys the LSB data. Any pipeline that includes lossy re-encoding — including platform processing that resizes or recompresses images, CDN transformations, or screenshots — can corrupt the hidden watermark.

The GeoImageTagger Watermark Tool uses steganographic encoding with a built-in verifier that extracts and validates the hidden payload. The tool requires PNG export to ensure lossless preservation of the encoded data.

PDF Watermark Overlay Rendering

Watermarking PDFs is architecturally different from images. A PDF is not a flat pixel grid — it is a structured document with text objects, font references, vector graphics, annotations, and hyperlinks.

The correct approach renders the watermark as a new content layer on each page without rasterizing the existing content. A browser-based implementation can use a JavaScript PDF library to:

  1. Load the existing PDF document.
  2. Iterate through each page.
  3. Draw watermark text or images onto each page's content stream.
  4. Export the modified PDF.

The result preserves selectable text, clickable hyperlinks, and original page dimensions. This is fundamentally different from screenshot-based approaches that flatten the PDF to a raster image — destroying all interactive content.

Format-Specific Export Considerations

Export Format Compression Hidden Watermark Quality Control
PNG Lossless Preserved N/A (always lossless)
JPG Lossy (DCT) Destroyed Quality slider (0–100%)
WebP Lossy (predictive) Destroyed Quality slider (0–100%)
PDF Vector/mixed N/A Original quality preserved

For hidden watermarks, PNG is non-negotiable. For visible-only watermarks, JPG at 90%+ quality provides the best file-size-to-quality ratio for web publishing.

Client-Side Architecture

Running watermarking client-side eliminates server infrastructure costs and privacy concerns. A browser-based watermark tool can use standard web APIs such as:

  • File input APIs for reading user files
  • <canvas> for image compositing and pixel manipulation
  • Canvas export methods for format conversion
  • A JavaScript PDF library for PDF manipulation
  • Blob URLs for download triggers

No file data crosses the network. This architecture is particularly important for sensitive documents and images where server uploads would introduce privacy and compliance risks.

For a practical guide covering all watermark types from a user perspective, see the full article on how to add watermarks to photos and PDFs. The GeoImageTagger Watermark Tool provides all of these capabilities in a free, browser-based interface.

Top comments (0)