IDWatermark
A modern library for creating holographic watermarks in images using OffscreenCanvas. Perfect for document protection, digital certificates, or any image requiring a holographic watermark effect.
Spanish: Read here.
Features
- ✨ Customizable holographic effects
- 🎨 Full control over colors and gradients
- 🖼️ Support for multiple image formats
- 🚀 Optimized performance with OffscreenCanvas
- 👷 Web Workers compatible
- 🔄 Asynchronous processing

Installation
npm install @videsk/id-watermark
Basic Usage
import IDWatermark from '@videsk/id-watermark';
const watermarker = new IDWatermark();
const imageBlob = await fetch('image.jpg').then(r => r.blob());
const watermarkedBlob = await watermarker.addWatermark(imageBlob, 'CONFIDENTIAL');
Configuration
The library accepts the following configuration options:
const watermarker = new IDWatermark({
fontSize: 12,
fontFamily: 'Courier New',
opacity: 1,
baseHue: 270,
hueStep: 3,
grayscale: false,
bitmapOptions: {}
});
Understanding Hue Values
The holographic effect is based on HSL (Hue, Saturation, Lightness) color space manipulation. The hue
parameter determines the base color and its progression:
baseHue (0-360)
The baseHue
value represents the initial color in the chromatic circle:
- 0/360: Red
- 60: Yellow
- 120: Green
- 180: Cyan
- 240: Blue
- 270: Violet (default value)
- 300: Magenta
hueStep
The hueStep
controls how much the color changes between consecutive characters:
- Low values (1-5): Smooth and gradual changes
- Medium values (5-15): Moderate rainbow effect
- High values (15+): Dramatic color changes
Combination Examples
const subtleHolographic = new IDWatermark({
baseHue: 270,
hueStep: 3
});
const rainbowEffect = new IDWatermark({
baseHue: 0,
hueStep: 15
});
const blueMonochrome = new IDWatermark({
baseHue: 240,
hueStep: 1
});
API
Main Methods
addWatermark(imageInput, watermarkText, encodeOptions)
Adds a watermark to an image.
const result = await watermarker.addWatermark(
imageBlob,
'CONFIDENTIAL',
{ type: 'image/jpeg', quality: 0.9 }
);
Parameters
imageInput
: File | Blob | ImageData | ImageBitmap | OffscreenCanvas | VideoFrame | HTMLImageElementwatermarkText
: stringencodeOptions
: Object (optional)
type
: string (e.g., 'image/jpeg', 'image/png')quality
: number (0-1)
Configurable Properties
All properties can be modified at runtime:
watermarker.fontSize = 24;
watermarker.opacity = 0.7;
watermarker.baseHue = 180;
Web Workers Usage (Conceptual Example)
const worker = new Worker('watermark.worker.js', { type: 'module' });
worker.postMessage({
type: 'ADD_WATERMARK',
payload: {
image: imageBlob,
text: 'CONFIDENTIAL',
options: { baseHue: 270, hueStep: 3 }
}
}, [imageBlob]);
worker.onmessage = (e) => {
if (e.data.type === 'WATERMARK_COMPLETE') {
const watermarkedBlob = e.data.payload;
}
};
Browser Compatibility
- Modern browsers with OffscreenCanvas support
- Chrome 69+
- Firefox 79+
- Edge 79+
- Safari 16.4+
License
MIT