0.0.1 • Published 7 months ago

@slaykit/watermark v0.0.1

Weekly downloads
-
License
-
Repository
-
Last release
7 months ago

🔥 Watermark Plugin

A lightweight and customizable JavaScript class for generating watermarks on a canvas element. The plugin supports both text and image-based watermarks with configurable options.


✨ Features

  • Generate watermarks using either text or images.
  • Highly customizable options, including font, color, spacing, size, and rotation.
  • Supports high-definition displays with device pixel ratio adjustment.
  • Works in modern browsers with canvas support.

📦 Installation

Install the plugin via npm or yarn or pnpm:

# Using npm
npm install @slaykit/watermark --save-dev

# Using yarn
yarn add @slaykit/watermark --dev

# Using pnpm
pnpm add @slaykit/watermark --save-dev

🚀 Usage

Example: Text-based Watermark

const options = {
  content: 'SlayKit',
  fontSize: 20,
  fontColor: 'rgba(0, 0, 0, 0.1)',
  rotate: -30,
};

const watermark = new Watermark(options);
watermark.create().then((dataURL) => {
  document.body.style.backgroundImage = `url(${dataURL})`;
});

Example: Image-based Watermark

const options = {
  image: 'https://xulai.me/favicon.svg',
  width: 150,
  height: 100,
  gapX: 300,
  gapY: 200,
};

const watermark = new Watermark(options);
watermark.create().then((dataURL) => {
  document.body.style.backgroundImage = `url(${dataURL})`;
});

⚙️ API Reference

WatermarkOptions

PropertyTypeDefaultDescription
contentstring | string[]nullWatermark text content. Can be a single string or an array of strings for multi-line watermarks.
rotatenumber-22Rotation angle of the watermark in degrees.
imagestringnullURL of an image to be used as the watermark.
opacitynumber1Opacity of the watermark in
gapXnumber212Horizontal spacing between watermarks.
gapYnumber222Vertical spacing between watermarks.
widthnumber120Width of the watermark.
heightnumber64Height of the watermark.
offsetLeftnumbergapX / 2Horizontal offset of the watermark.
offsetTopnumbergapY / 2Vertical offset of the watermark.
fontSizenumber16Font size for text watermarks.
fontFamilystringsans-serifFont family for text watermarks.
fontWeight"normal" | "light" | "weight" | numbernormalFont weight for text watermarks.
fontColorstringrgba(0,0,0,.15)Font color for text watermarks.
fontStyleCanvasFillStrokeStyles"fillStyle"normalText style for text watermarks.

贡献

如果你有任何改进建议或发现了问题,欢迎通过 GitHub Issues 向我们反馈,或者提交 Pull Request。

0.0.1

7 months ago