A web watermark SDK, support: custom watermark content and style, watermark encryption and decryption, watermark anomaly monitoring, etc.

Overview

English | 简体中文

1. What is l-watermark?

l-watermark is a web watermark SDK based on TS, which contains:

  • Can cover more than scene watermarking method
    1. Add text/picture watermark to webpage
    2. Add text/picture watermark to picture
    3. Add a 'hidden watermark' to the picture
    4. Decrypt hidden watermark images
  • Guard the watermark from being tampered with and deleted
  • Provides a variety of callback functions
    1. onchange: a callback when a user attempts to tamper with or delete a watermark, at which point you get the user ID and report it to the server
    2. onerror: the callback when the watermark failed to be added, you can see why the watermark failed to be added
    3. success: you can get the watermarked image base64 as a callback when the watermark is successfully added
  • Custom watermark style
    1. Customize color, font size, hierarchy, spacing, transparency, rotation angle, etc
    2. Customize the watermark position in the picture: full, middle, upper left corner, lower right corner, etc

2. Install

2.1 npm

npm install l-watermark
import WaterMark from "l-watermark"

2.2 CDN

You can get the latest SDK at unpkg.com/l-watermark, or you can specify @x.x.x'to get a specific version of the SDK, and then import it at the appropriate location

<script src="https://unpkg.com/[email protected]/dist/l-watermark.umd.js"></script>

3 Demo

3.1 Add watermarks to webpage

3.1.1 Full screen text watermark

WaterMark.page({
  containerEl: document.body,
  text: "Internal Data",
  color: "rgba(0, 0, 0, 0.4)",
  fontSize: 24
})

page-demo-1

3.1.2 Partial area of the image watermark

WaterMark.page({
  containerEl: document.getElementById("hello_world"),
  image: "https://cdn.jsdelivr.net/gh/CleverLiurx/image_repo/glass15-wm.png",
  cSpace: 20,
  vSpace: 50
})

image-demo-8

3.2 Add watermarks to picture

3.2.1 Text watermarking

WaterMark.image({
  target: document.getElementById('demo-image'),
  text: 'Angelababy',
  cSpace: 20,
  color: 'rgba(0,0,0,0.6)',
  fontSize: 20,
})

image-demo-1

3.2.2 Image watermarking

WaterMark.image({
  target: document.getElementById('demo-image'),
  image: "https://cdn.jsdelivr.net/gh/CleverLiurx/image_repo/glass15-wm.png",
  cSpace: 20,
  vSpace: 20,
  imageWidth: 60,
  imageHeight: 40
})

image-demo-2

3.2.3 Adds a watermark at the specified location

// Add text watermark in the lower right corner of the photo
WaterMark.image({
  target: document.getElementById('demo-image'),
  position: "bottomRight",
  text: '@ GitHub - CleverLiurx',
  color: 'rgba(255, 0, 0, 1)',
  fontSize: 20,
  cSpace: 20,
  vSpace: 10,
})

image-demo-3

// Add the image watermark to the top left corner of the photo
WaterMark.image({
  target: document.getElementById('demo-image'),
  position: "topLeft",
  image: "https://cdn.jsdelivr.net/gh/CleverLiurx/image_repo/glass15-wm.png",
  imageWidth: 100,
  imageHeight: 60,
  cSpace: 20,
  vSpace: 20
})

image-demo-4

3.2.4 Get the base64 format of the watermark image

When target is not HTMLImageElement, the page will not change after watermarking, but you can get the base64 watermarked image through the success callback function

WaterMark.image({
  target: "https://cdn.jsdelivr.net/gh/CleverLiurx/image_repo/ab-v1.0.0-demo.png",
  text: 'Angelababy',
  cSpace: 100,
  success: (data) => console.log(data),
})

image-demo-5

3.2.5 Encryption/decryption of hidden watermark

To set hidden watermarking, just set secret to true, but this version only supports text mode, not image mode

WaterMark.image({
  target: document.getElementById("demo-image"),
  text: "User Id: 1008611",
  position: 'center',
  secret: true,
})

After adding the hidden watermark, the naked eye will look no different from the original image

image-demo-7

However, after the hidden watermark decryption tool is called, the watermark text is displayed

const decodeImage = async () => {
  const imgDom = document.getElementById("demo-image")
  const decodeSrc = await WaterMark.utils.decodeImage(imgDom.src)
  imgDom.src = decodeSrc
}

image-demo-6

4. Options

4.1 WaterMark.page(PageOp)

This is the configuration item when the WaterMark.page(PageOp) function is called to add a watermark to the page


Options Default Explain Type
text Demo Text watermark text (conflicts with image) string
image watermark image (conflicts with text) string(img.src)
containerEl document.body the element to be watermarked HTMLElement
color "rgba(0, 0, 0, 0.15)" color of text string
fontSize 24 font size of text number
zIndex "10000" css: z-index string
cSpace 0 the crosswise spacing between individual watermarks number
vSpace 0 the vertical spacing between individual watermarks number
angle -25 rotation angle of text number
onchange a callback function when the watermark is tampered with or deleted Function
onerror a callback function in case of error adding watermark Function(ErrorMessage)
success the callback function after successfully adding watermark Function

4.2 WaterMark.image(ImageOp)

This is the configuration item when the WaterMark.image(ImageOp) function is called to add a watermark to the picture


Options Default Explain Type
target the target to watermark HTMLImageElement|string(img.src)
text "Demo Text" watermark text (conflicts with image) string
image watermark image (conflicts with text) string(img.src)
imageWidth the width of the image number
imageHeight the width of the height number
secret false whether to add a hidden watermark boolean
color "rgba(0, 0, 0, 0.15)" color of text string
fontSize 24 font size of text number
position "repeat" the location of the watermark (default covered with target, other options is add a watermark at the specified location) string(repeat |center |bottomRight |bottomLeft |topLeft |topRight)
cSpace 0 the crosswise spacing between individual watermarks number
vSpace 0 the vertical spacing between individual watermarks number
angle -25 rotation angle of text number
success he callback function after successfully adding watermark Function
onerror a callback function in case of error adding watermark Function(ErrorMessage)

NOTE:img.src means that it can be a image path、URL address or base64

4.3 WaterMark.utils

4.3.1 Decrypt hidden watermark images

Receives a string argument (img.src) and returns Promise<string>

const imgBase64 = await WaterMark.utils.decodeImage(url)

4.3.2 Add hidden watermark

Of course you can use the success callback in WaterMarking. image (ImageOp) to get the watermarked image, but we also provide a utility function that let's you add hidden watermark to the image and get its base64, which returns Promise<string>

const imgBase64 = await WaterMark.utils.decodeImage({ImageOp})
You might also like...

Onchain private messaging app with a significant encryption algorithm.

Onchain private messaging app with a significant encryption algorithm.

Hedwig DEMO We want to implement SSL technology to blockchain so decided to build onchain private messaging app. Diffie Hellman protocol was invented

Nov 3, 2022

we learn the whole concept of JS including Basics like Object, Functions, Array etc. And Advance JS - Understanding DOMs, JQuery, Ajax, Prototypes etc.

JavaScript-for-Complete-Web Development. we learn the whole concept of JS including Basics like Object, Functions, Array etc. And Advance JS - Underst

Jul 22, 2022

Query for CSS brower support data, combined from caniuse and MDN, including version support started and global support percentages.

css-browser-support Query for CSS browser support data, combined from caniuse and MDN, including version support started and global support percentage

Nov 2, 2022

Tools to check version monitoring (updates) for web application. web 应用版本监测(更新)工具库

Tools to check version monitoring (updates) for web application. web 应用版本监测(更新)工具库

🔔 version-rocket 🚀 English | 简体中文 Notify users when a new version of your site is available and prompt them to refresh the page. When you finish dep

Dec 29, 2022

Examples of how to do query, style, dom, ajax, event etc like jQuery with plain javascript.

You (Might) Don't Need jQuery Frontend environments evolve rapidly nowadays and modern browsers have already implemented a great deal of DOM/BOM APIs

Dec 24, 2022

Telegram BOT For TikTok/Douyin downloader (TikTok video downloader without watermark)

TikDo Telegram BOT This is BOT Telegram downloader TikTok/Douyin. Download videos without watermark by pasting share link in send message. How to depl

Dec 1, 2022

Base62-token.js - Generate & Verify GitHub-style & npm-style Base62 Tokens

base62-token.js Generate & Verify GitHub-style & npm-style Secure Base62 Tokens Works in Vanilla JS (Browsers), Node.js, and Webpack. Online Demo See

Jun 11, 2022

A Javascript based web application for monitoring, analytics and notifications

JELLYWATCH Jellywatch is a javascript web application for monitoring*, analytics** and notifications** inspired by tautulli for Jellyfin/Emby Media Se

Dec 28, 2022

A custom Chakra UI component that adds ready-made styles for rendering remote HTML content.

Chakra UI Prose Prose is a Chakra UI component that adds a ready-made typography styles when rendering remote HTML. Installation yarn add @nikolovlaza

Jan 3, 2023
Comments
  • page 水印文字模糊

    page 水印文字模糊

    看起来是 canvas 绘图共有的问题,能否优化一下呢 @CleverLiurx

    const watermark = WaterMark.page({
      containerEl: document.body,
      text: '预览模式',
      color: `${theme.semanticColors.bodyText}44`,
      fontSize: 16,
      vSpace: 35,
      cSpace: 35,
    });
    
    image
    opened by ikkz 3
  • 页面出现了多个水印

    页面出现了多个水印

    使用中发现当手动改变水印元素的属性时会重新添加一个新的水印,原来的水印并没有移除掉,页面上就同时出现了多个水印叠加

    https://github.com/CleverLiurx/l-watermark/blob/1f351cc4081e06bec9b34a0d2d3161e2166adc0f/src/guard-dom.ts#L53-L55

    这里新添加元素之后 GuardDom.target 也没有和 PageWaterMark.watermakr 同步,导致 PageWaterMark.remove 只能移除掉最开始的那个水印元素

    opened by ikkz 1
Owner
Liurx
微信公众号@ WEB实习僧
Liurx
The iofod SDK provides developers with the ability to interact with the main iofod interface within the Web worker, enabling rapid development of iofod extensions through the SDK.

iofod-sdk English | 简体中文 The iofod SDK provides developers with the ability to interact with the main iofod interface within the Web worker, enabling

iofod, Inc. 47 Oct 17, 2022
Activate The Open Web ™ ("Activate Windows" watermark ported to the web)

Activate-Web The "Activate Windows" watermark ported to Open Web ™. Inspired by activate-linux. As of 0.1, it’s a Web Component written in TypeScript,

Blair Noctis 8 Jun 6, 2022
Kuldeep 2 Jun 21, 2022
Movehat is a TypeScript SDK for Move on Sui built on top of Sui's TypeScript SDK and our fork of Ian Macalinao's `move-ts`.

Movehat Movehat is a TypeScript SDK for Move on Sui built on top of Sui's TypeScript SDK and our fork of Ian Macalinao's move-ts. Movehat aspires to b

Pentagon 10 Sep 30, 2022
Next-gen mobile first analytics server (think Mixpanel, Google Analytics) with built-in encryption supporting HTTP2 and gRPC. Node.js, headless, API-only, horizontally scaleable.

Introduction to Awacs Next-gen behavior analysis server (think Mixpanel, Google Analytics) with built-in encryption supporting HTTP2 and gRPC. Node.js

Socketkit 52 Dec 19, 2022
A Hackable Markdown Note Application for Programmers. Version control, AI completion, mind map, documents encryption, code snippet running, integrated terminal, chart embedding, HTML applets, plug-in, and macro replacement.

Yank Note A hackable markdown note application for programmers Download | Try it Online >>> Not ecommended English | 中文说明 [toc]{level: [2]} Highlights

洋子 4.3k Dec 31, 2022
A small utility server to exchange data and messages between clients. Comes complete with E2E public key encryption

Zenotta Intercom A small utility server to exchange arbitrary data between clients. Comes complete with E2E public key encryption Official documentati

Zenotta AG 7 Oct 2, 2022
A fully cross-platform messenger app with End to End Encryption (E2EE).

Smartsapp A fully cross-platform messenger app with End to End Encryption (E2EE). Demo NOTE: The features shown in the demo is not exhaustive. Only th

Derek Jones 13 Aug 25, 2022
Timelock Encryption made practical. A Typescript library for encrypting for the future.

tlock-js A typescript library for encrypting data which can only be decrypted at a set time in the future using drand. tlock-js uses AGE to symmetrica

drand 54 Dec 1, 2022
A file-sharing app providing end-to-end encryption of data.

secsend secsend is a file-sharing app providing end-to-end encryption of data. It provides a web application and a command-line interface (CLI). demo.

Adrien Guinet 28 Dec 22, 2022