Skip to content

Repository files navigation

TextWatermark

TextWatermark is a library for inserting watermarks into text

Please take a look at our documentation for how to install and use TextWatermark:

Requirements

Tested on Python >= 3.10

Installation

Using Pip

$ pip install textwatermark

From Code

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

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

Export watermark parameters

$ 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": 1, "wm_mode": 5, "wm_len": 7, "wm_loop": false, "start_at": 0, "version": "0.1.2"}

Retrieve the watermark from the text

$ textwatermark -v retrieve -f out.txt -p '{"tpl_type": "HOMOGRAPH_NUMBERS", "confusables_chars": [], "confusables_chars_key": "", "wm_base": 7, "method": 1, "wm_mode": 5, "wm_len": 7, "wm_loop": false, "start_at": 0, "version": "0.1.2"}'The retrieved watermark is: 123

Coding

'''Sample Example'''importosfromtextwatermark.definesimportWMModefromtextwatermark.mainimportTextWatermarkfromtextwatermark.template_typeimportWMTemplateType# 1.Init TextWatermark instancewm_mode=WMMode.REAL_NUMBERwm=TextWatermark(wm_mode=wm_mode)
# 2.Choose a watermark templatewm.set_tpl_type(tpl_type=WMTemplateType.HOMOGRAPH_NUMBERS)
# 3.Set the maximum value of the watermark stringwm_max='9'*9wm.set_wm_max(wm_max=wm_max)
# 4.Set the text to be watermarkedwm.set_text_file(path=os.path.abspath('../tests/text/1.txt'))
# 5.Insert watermark string to textwm_str='123456789'wm_text=wm.insert_watermark(wm_str=wm_str)
print(wm_text)
############################################################### Save the parameters to retrieve the watermarkparams=wm.export_params()
# retrieve the watermarkwm_out_str=TextWatermark.retrieve_watermark(wm_text=wm_text, params=params)
assertwm_out_str==wm_str

More

See: Documents

About

Watermark For Text

Resources

Stars

22 stars

Watchers

3 watching

Forks

Releases

Used by

Contributors

Languages