Adding image watermarks

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Watermark MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-watermark -- dnx GroupDocs.Watermark.Mcp --yes
Folders, licensing and more →

GroupDocs.Watermark supports adding the following image formats as watermarks:

  • BMP
  • PNG
  • GIF
  • JPEG

Add an image watermark from a local file

The following example adds an ImageWatermark to a document. If the document consists of multiple parts (pages, worksheets, slides, frames, etc.), the watermark is added to each of them.

from groupdocs.watermark import Watermarker
from groupdocs.watermark.watermarks import ImageWatermark, SizingType
from groupdocs.watermark.common import HorizontalAlignment, VerticalAlignment

def add_image_watermark():
    with Watermarker("./sample.docx") as watermarker:
        with ImageWatermark("./logo.png") as watermark:
            watermark.horizontal_alignment = HorizontalAlignment.CENTER
            watermark.vertical_alignment = VerticalAlignment.CENTER
            watermark.sizing_type = SizingType.SCALE_TO_PARENT_DIMENSIONS
            watermark.scale_factor = 0.5
            watermark.opacity = 0.7
            watermarker.add(watermark)
        watermarker.save("./output.docx")

if __name__ == "__main__":
    add_image_watermark()

sample.docx and logo.png are the sample files used in this example. Download sample.docx and logo.png.

Binary file (DOCX, 127 KB)

Download full output

Add an image watermark from a stream

You can also initialize an ImageWatermark from a stream — pass it as the stream argument.

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

def add_image_watermark_from_stream():
    with open("./logo.png", "rb") as f:
        data = f.read()

    with Watermarker("./sample.docx") as watermarker:
        with ImageWatermark(stream=io.BytesIO(data)) as watermark:
            watermarker.add(watermark)
        watermarker.save("./output.docx")

if __name__ == "__main__":
    add_image_watermark_from_stream()

sample.docx and logo.png are the sample files used in this example. Download sample.docx and logo.png.

Binary file (DOCX, 121 KB)

Download full output

For advanced watermark properties (tiling, alignment, sizing, rotation, and margins), the same techniques shown for text watermarks apply to image watermarks. See Adding text watermarks.