Skip to content

Home

Home

TextWatermark Templates Support and Compatibility

WMTemplateType
模板参数
Applicable scene
适用场景
Text featureless
文本无特征
Support characters
支持字符
Plain Text
纯文本
Concealment
隐蔽性
Paste
粘贴
Screenshot
截图
Photograph
屏摄
Format
格式
Style
样式
Shape
字形
Meaning
字义
Number
数字
Letter
字母
Chinese
汉字
Special
特殊
INVISIBLE_CHARS
不可见字符
× × High
WHITESPACE_CHARS
空白字符
× × Medium
SPACE_CHARS
空格字符
× × × × Medium
COMBINING_CHARS
组合字符
× Medium
HOMOGRAPH_NUMBERS
同形异义-数字
× × × × Low
HOMOGRAPH_LETTERS
同形异义-字母
× × × × × × Low
HOMOGRAPH_CHINESE
同形异义-中文
× × × × × Low
HOMOGRAPH_PUNCTUATIONS
同形异义-标点
× × × × × Medium
FONT_COLOR
字体颜色
× × Medium
FONT_SIZE
字体大小
× × Low
FONT_WEIGHT
字体粗细
× × Low
FONT_FLOAT
字体浮动
× × Low
FONT_STYLE
自定义样式
× × Low
HTML_EMPTY_TAGS
空HTML实体
× × × Low
BINARY_REPRESENTATION
二进制表示
High

Requirements

Tested on Python >= 3.10

Installation

Using Pip

$ pip install textwatermark

From Code

Bash
git clone https://github.com/JDArmy/TextWatermark.git

cd TextWatermark

pip install .

# or in editable mode
pip install --editable .

Usage

CMD Line

Insert watermark into text
Bash Session
$ textwatermark -v insert -f './tests/text/number.txt' -m ALPHA_NUMERICAL -t HOMOGRAPH_NUMBERS -x 999 -w 123

Ӏ2𝟑𝟒𝟓Ⳓ𝟟890
Export watermark parameters
Bash Session
$ textwatermark -v insert -f './tests/text/number.txt' -m ALPHA_NUMERICAL -t HOMOGRAPH_NUMBERS -x 999 -w 123 -e

{"tpl_type": "HOMOGRAPH_NUMBERS", "confusables_chars": [], "confusables_chars_key": "", "wm_base": 7, "method": "FIND_AND_REPLACE", "wm_mode": "ALPHA_NUMERICAL", "wm_len": 7, "wm_flag_bit": true, "wm_loop": false, "wm_max": "999", "start_at": 0, "version": "0.3.0"}
Retrieve the watermark from the text
Bash Session
$ textwatermark -v retrieve -f out.txt -p '{"tpl_type": "HOMOGRAPH_NUMBERS", "confusables_chars": [], "confusables_chars_key": "", "wm_base": 7, "method": "FIND_AND_REPLACE", "wm_mode": "ALPHA_NUMERICAL", "wm_len": 7, "wm_flag_bit": true, "wm_loop": false, "wm_max": "999", "start_at": 0, "version": "0.3.0"}'

The retrieved watermark is: 123

Coding

Python
'''Sample Example'''
import os

from textwatermark.defines import WMMode
from textwatermark.main import TextWatermark
from textwatermark.template_type import WMTemplateType

# 1.Init TextWatermark instance
wm_mode = WMMode.REAL_NUMBER
wm = TextWatermark(wm_mode=wm_mode)

# 2.Choose a watermark template
wm.set_tpl_type(tpl_type=WMTemplateType.HOMOGRAPH_NUMBERS)

# 3.Set the maximum value of the watermark string
wm_max = '9'*9
wm.set_wm_max(wm_max=wm_max)

# 4.Set the text to be watermarked
wm.set_text_file(path=os.path.abspath('../tests/text/1.txt'))

# 5.Insert watermark string to text
wm_str = '123456789'
wm_text = wm.insert_watermark(wm_str=wm_str)
print(wm_text)

##############################################################

# Save the parameters to retrieve the watermark
params = wm.export_params()

# retrieve the watermark
wm_out_str = TextWatermark.retrieve_watermark(wm_text=wm_text, params=params)

assert wm_out_str == wm_str

More

See: Usage