Invisible Watermark

0.2.0 · active · verified Thu Apr 16

Invisible Watermark is a Python library designed for robustly embedding and extracting invisible watermarks within images. It provides functionalities to encode arbitrary text or data into an image without perceptibly altering its visual appearance, and subsequently decode the hidden information. The library is actively developed, currently at version 0.2.0, with releases occurring periodically to introduce features and fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a dummy image, then initialize the InvisibleWatermark library to encode a text watermark into it, and finally decode the watermark from the saved output image.

import os
from PIL import Image
from invisible_watermark import InvisibleWatermark

# 1. Create a dummy image for demonstration if it doesn't exist
image_filename = "dummy_input_image.png"
output_filename = "dummy_watermarked_image.png"

if not os.path.exists(image_filename):
    img = Image.new('RGB', (256, 256), color = 'red')
    img.save(image_filename)
    print(f"Created dummy image: {image_filename}")

# 2. Initialize the watermark library
iwm = InvisibleWatermark()

# 3. Define the watermark text
watermark_text = "SecretMessage123"
print(f"Original watermark: {watermark_text}")

# 4. Encode the watermark into the image
iwm.encode(image_filename, output_filename, watermark_text)
print(f"Watermark encoded and saved to: {output_filename}")

# 5. Decode the watermark from the watermarked image
decoded_text = iwm.decode(output_filename)
print(f"Decoded watermark: {decoded_text}")

# 6. Clean up generated files (optional)
# os.remove(image_filename)
# os.remove(output_filename)

view raw JSON →