Nodes/comfyUI-tool-2lab/calculate watermark offset 计算水印在主图上的坐标
ComfyUI Node

calculate watermark offset 计算水印在主图上的坐标

Pixel math for watermark placement, solved

By AI2lab·Created 2 years ago·Updated 2 years ago· 23
calculate watermark offset 计算水印在主图上的坐标
  • image
  • watermarkImage
  • xOffset
  • yOffset
locationbottom-right
margin_x0
margin_y0

Putting a watermark on an image sounds easy until you actually do it in ComfyUI. You need the watermark's size, the main image's size, a chosen corner, and then - unless you enjoy doing width-minus-width math in your head - you need to compute the pixel offset where the watermark should go. That arithmetic is exactly what WatermarkOffset (2lab) does: give it the main image, the watermark image, and a corner, and it returns the xOffset/yOffset pixel coordinates to feed your composite/paste node. No calculator required.

Why does this matter beyond convenience? Because any workflow that ships images - and this pack is built around publishing workflows to the 2lab server as APIs - almost always needs a watermark on output, and it needs it positioned exactly, every time, regardless of the incoming image size. Hard-coding offsets breaks the moment an input image is a different resolution. This node makes the placement adapt to whatever it's given.

Inputs

  • image - the main (background) image the watermark goes onto.
  • watermarkImage - the watermark image itself, presumably with transparency.
  • location - which corner: top-left, top-right, bottom-left, bottom-center, or bottom-right (default). Note the slightly odd lineup: bottom gets a center option, top doesn't. That's the author's call, and it covers the most common real-world choice (bottom-right is the default for a reason).
  • margin_x - extra horizontal padding from the chosen edge, in pixels (default 0).
  • margin_y - extra vertical padding, in pixels (default 0).

Outputs

  • xOffset - the horizontal pixel position where the watermark should be placed.
  • yOffset - the vertical pixel position.

Wire these two ints into your paste/composite node as the paste coordinates. That's the whole return: two numbers.

How it works

It reads the dimensions of both images, picks the anchor point based on location, subtracts the watermark's dimensions so it sits inside the chosen corner (or centered, for bottom-center), and adds your margins. The result is the top-left position where the watermark's own top-left corner belongs. Different main-image sizes in, correct offsets out - that's the adaptivity that hard-coding never gives you.

Installing it

Same as the rest of the pack. ComfyUI Manager → search "comfyUI-tool-2lab" → install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/AI2lab/comfyUI-tool-2lab

Restart ComfyUI. Pure Python, no model downloads.

Gotchas

  • It only calculates. This node gives you coordinates; it doesn't paste the watermark for you. You need a composite/paste node downstream that actually does the blending, fed by the two offset ints.
  • A watermark bigger than the image is your problem. If the watermark image is larger than the main image, the math can push the offset negative and the paste will look wrong. Keep the watermark smaller than the smallest main image you feed in.
  • Margin direction depends on the corner. A positive margin_x moves the watermark inward from whichever edge it's anchored to. With bottom-right (the default), it pushes up and left from the corner - which is what most people want, but confirm it once.
  • Repo visibility. The pack's GitHub page currently returns 404, likely made private or renamed. Fresh clones can fail while existing installs keep working - known quirk, not your error.
Category🦊2lab/image

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
watermarkImageIMAGE
locationCOMBObottom-right5 options: top-left, top-right, bottom-left, bottom-center, bottom-right
margin_xINT0
margin_yINT0

Outputs (2)

NameTypeDescription
xOffsetINT
yOffsetINT