Table of Contents

Class Watermark

Namespace
LMKit.Graphics
Assembly
LM-Kit.NET.dll

A visible watermark (a filigree): a line of text, a logo, or a logo beside a line of text. Burned into a picture's pixels by ApplyWatermark(Watermark), or laid over the pages of a PDF as vector artwork by PdfWatermarker.

public sealed class Watermark
Inheritance
Watermark
Inherited Members

Examples

using LMKit.Graphics;
using LMKit.Media.Image;

using ImageBuffer photo = ImageBuffer.Load("photo.jpg");
using ImageBuffer web = photo.Resize(1600, 1067);

web.ApplyWatermark(new Watermark
{
    Text = "© Northwind Studio",
    Layout = WatermarkLayout.Tile,
    Opacity = 0.35
});

web.SaveAsJpeg("photo-web.jpg", 90);

Remarks

Resolution independent. Every size is a fraction of the surface's shorter side, so a 400 pixel preview and the 8000 pixel master of the same image carry the same-looking mark, and so do an A4 page and a US Letter page. Apply the watermark to a picture after resizing, never before, so it is drawn crisp at the resolution the reader receives.

Legible on any surface. The mark is drawn with a contrasting halo, so a light mark still reads over a white sky and a dark one over a night scene. With Color left null the engine picks light or dark from what the mark covers.

Every script. Text is drawn with FontData when given, and otherwise with the host's installed fonts, choosing per character a font that covers it (Latin, Greek, Cyrillic, Arabic, Hebrew, Devanagari, Chinese, Japanese, Korean...). Arabic letters are joined and right-to-left text is put in reading order. A character no available font can draw fails the call with WatermarkCharactersException naming it, rather than a silent empty box.

A visible watermark deters reuse and states ownership; it does not trace a leak. On a picture, pair it with ImageRightsMetadata so the rights also travel machine-readable inside the file.

Fields

MaxTextLength

The longest Text accepted, in characters.

Properties

Angle

The mark's rotation in degrees, clockwise (as Rotate(int)), from -90 to 90. null (default) takes the layout's own: -30 (rising from left to right) for Tile, the surface's rising diagonal (at most 30 degrees) for Center, 0 for a corner.

Color

The mark's colour: the text's fill (a logo is never recoloured). null (default) chooses white or near-black from the brightness of what the mark covers.

FontData

Optional TrueType or OpenType font (a .ttf, .otf or .ttc file's bytes) the text is drawn with: a brand face. Characters it does not cover fall back to the host's installed fonts. null draws with the installed fonts, bold sans first.

Halo

Whether the mark carries a contrasting halo so it stays legible on light and dark areas alike. Default: true.

HasInstalledFonts

Whether any font is installed on this host. Without one, and without FontData, text is drawn with the built-in Helvetica Bold and limited to Western European characters.

Layout

Where the mark is drawn. Default: Tile.

Logo

An optional logo. Its alpha channel is honoured, so a transparent PNG mark sits on the surface without a box. Drawn alone, or at the start of the line when Text is set. The buffer is read, never modified or disposed.

Margin

The distance between a corner mark and the surface's edges, as a fraction of the shorter side, from 0 to 0.25. Default: 0.03.

Opacity

How opaque the mark is, from 0.02 (barely there) to 1 (solid). Default: 0.4.

Size

The mark's width as a fraction of the surface's shorter side, from 0.05 to 1. null (default) takes the layout's own: 0.3 for Tile, 0.6 for Center, 0.25 for a corner. A single mark is always shrunk as needed to fit inside the surface: it is never cut by an edge.

Spacing

The density of a Tile lattice, from 0.5 (dense) to 3 (sparse): the gap between marks scales with it. Default: 1.

Text

The line of text the mark carries, drawn on one line (line breaks become spaces). null or blank for a logo-only mark. At most 200 characters.

Share