Skip to content

API Reference

This section provides detailed documentation for the gwm.js API.

Overview

gwm.js exposes a global gwm object with the following methods:

MethodDescription
creation(options)Creates a watermark with the specified options.
observing()Manually starts observing the watermark for tampering.
cancel()Cancels observation and allows the watermark to be removed.

Basic Usage

javascript
// Create a watermark with default options
gwm.creation();

// Create a watermark with custom options
gwm.creation({
  txt: 'Confidential',
  fontSize: 14,
  color: '#ff0000'
});

// Manually observe the watermark
const observer = gwm.observing();

// Cancel observation
gwm.cancel();

Options

The creation method accepts an options object with the following properties:

PropertyTypeDefaultDescription
txtstringCurrent date + "Top secret"The text content of the watermark.
widthnumber158The width of the watermark canvas.
heightnumber100The height of the watermark canvas.
xnumber0The x-coordinate of the watermark text.
ynumber50The y-coordinate of the watermark text.
fontstring'Arial'The font family for the watermark text.
fontSizenumber12The font size for the watermark text.
colorstring'#000'The color of the watermark text.
alphanumber0.1The transparency of the watermark (0-1).
anglenumber-15The rotation angle of the watermark text.
modestring'canvas'The rendering mode ('canvas', 'svg', or 'element').
watchbooleantrueWhether to monitor for tampering.
cssobjectnullCustom CSS styles for the watermark container.
destroybooleantrueDeprecated. Previously prevented multiple calls to creation, now has no effect.
containerstring | HTMLElementdocument.bodyThe container element for the watermark.
countnumbernullOptional parameter to set the number of watermarks.

For more detailed information about each option, see the table above. (Options page link removed)

Return Values

creation()

Returns: undefined

The creation method does not return a value. It creates a watermark and adds it to the DOM.

observing()

Returns: GwmObserver | GwmObserverEvent

The observing method returns an observer object that can be used to manually control the observation.

cancel()

Returns: void

The cancel method does not return a value. It cancels the current observation.

Type Definitions

(Types page link removed)