__init__ constructor

init

Initializes a new ImageWatermark instance with a specified file path.

def __init__(self, file_path):
    ...
Parameter Type Description
file_path str The path to the image that will be used as watermark.

Example

from groupdocs.watermark.watermarks import ImageWatermark

# Initialize an image watermark from a file path
watermark = ImageWatermark("logo.png")

init

Initializes a new ImageWatermark instance using the provided image stream.

def __init__(self, stream):
    ...
Parameter Type Description
stream io.RawIOBase The stream containing the image that will be used as watermark.

Example

import io
from groupdocs.watermark import Watermarker
from groupdocs.watermark.watermarks import ImageWatermark

# Load image data into a memory stream
with open("watermark.jpg", "rb") as f:
    data = f.read()

# Create a watermarker for the target document
with Watermarker("document.docx") as watermarker:
    # Initialize the image watermark from the stream
    with ImageWatermark(io.BytesIO(data)) as watermark:
        watermarker.add(watermark)
        watermarker.save("watermarked.docx")

See Also