Skip to main content

A watermark library for text.

Project description

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'''
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: Documents

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textwatermark-0.1.3.tar.gz (34.6 kB view details)

Uploaded Source

Built Distribution

textwatermark-0.1.3-py3-none-any.whl (42.4 kB view details)

Uploaded Python 3

File details

Details for the file textwatermark-0.1.3.tar.gz.

File metadata

  • Download URL: textwatermark-0.1.3.tar.gz
  • Upload date:
  • Size: 34.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for textwatermark-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a1790c8eb2ec1971f6c33ad823fc7458848961889e5432a5fafa755e29ca003d
MD5 55d67ef68d166f9dcd723ac9171d0b3e
BLAKE2b-256 3c5c7de6c88ea3e114155ca30405bdfc694cbe072dba77197e4529f7046ad5ff

See more details on using hashes here.

File details

Details for the file textwatermark-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for textwatermark-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 82051221a48dfc61e69b11287416dd5e1ed0bd934472831e0bb36611263e23b9
MD5 afcf20c8cc85c78aad6d6a59a341d920
BLAKE2b-256 8f070d9f1a40aeb4aadf9cbb241a1719b8ffe62c8c7c8a442a709ad66495a663

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page