Sign In

Automation: Watermarking Media

9

Automation: Watermarking Media

THE SITUATION

A talented content creator here on Civitai discovered his work was being stolen, reposted, and monetized on another site.  See his post about it here.  He recommended watermarking your work, which I highly endorse.

A while back, I cooked up a rough Python script that slaps a watermark PNG onto the bottom right of either images or video files.  I wanted to share it with you, gentle readers.

You'll find watermarker.py attached to this post.  Go on, click and download it.  I'll wait here.


THE DISCLAIMER

I am a veteran programmer of several languages, but I'm relatively new to Python.  It works but it probably could be written better.  ¯\_(ツ)_/¯

  • USE AT YOUR OWN RISK - This script is benign but you should ALWAYS read and understand what a script is doing BEFORE you run it.  If ya don't understand it, use ChatGPT to explain it.  I am not responsible for damages of any sort.  Lalala, not hearing you.

  • I will not provide support for this script. 

    • You will need Python installed

    • You will need to install the Python libraries used in this script.
      Use this: pip install opencv-contrib-python pillow numpy

      • opencv-contrib-python - video processing

      • numpy - handles blending watermark 

      • pillow - Image handling

I love and respect you, gentle reader, but if you come at me with bad questions, I will gladly tell you to…

image.png

WHAT IT DOES

The script will apply a watermark image of your choice to images or videos.  The watermark will be applied to the bottom right corner of your media.  If you want something centered you can either make a watermark image slightly smaller than your original dimensions or, if you're clever, you can edit the script yourself.  The watermark will be scaled down if it is larger than the media... or it might björk out.  Fuck around and find out, I say!

The script will make a copy of the media, so your original work is safe.  Images will be dropped into a new folder.  Videos will be left in the same folder because I'm too lazy to tinker with this thing any further.  

It will handle JPG, PNG, and MP4 files.  Anything else will probably not work.  I strongly suggest using a PNG for the watermark file since that supports transparency.

The script will copy EXIF data over if you're dealing with JPG files.  You're welcome.

All ya need to do is execute the script like so...

python watermarker.py

It will prompt you for the watermark file (if it can't find what is defined as DEFAULT_WATERMARK).  Next, it will prompt you for the target files.  Select as many as ya like, I don't mind.  Maybe your computer won't, either?

Here's an example of the results:

Watermarkery.jpg

Look, it's a hideous watermark!  HUZZAH!

I tried to upload a video example into the article but, alas, this interface just won't let me.  

Hope this script helps you somehow.  Let me know if ya like it.  I have a few other automation scriptie things I may post if there's a response.  

9