Alter the color of a watermark preset based on background color

I put a little signature/watermark in the corner of pictures I export. Most of the time, just using a white signature works just fine. However, a black signature sometimes would be better - maybe the colors are too light in that area for white to be seen. So my question is: Can I set the color of the watermark based on the (average) color behind it? I couldn’t see any obvious settings in the watermark module, so I’m thinking possibly Lua scripting? Although I haven’t gotten the hang of what exactly is exposed with the Lua API :stuck_out_tongue_winking_eye:

I normally do it in a batch with ImageMagick or G’MIC. I am too tired to provide examples but I am sure someone else can help you.

1 Like

Hmmm…okay, thanks. I’ll check out G’MIC :slight_smile:

This thread might be a good starting point: Annotation with Imagemagick (Watermark -ish)

1 Like

You can’t automate it, but at least you can use the color selector in the watermark module to choose a color. To use that in your watermark you have to open it in a text editor, find where the color is set (something like fill:#ff00ff) and replace that with the color variable (fill:$(WATERMARK_COLOR) in our example).
It lacks a color picker and is not automated, but maybe it helps somewhat.

1 Like

Hmmm okay. For now, I just created two presets and I manually went through the ones I was exporting and set the proper preset. Maybe we could introduce a general-purpose automation of this kind for presets? I feel like it may be useful in other situations as well (e.g. frame color depending on dominant color at the edges). Something like parameters of the preset/module can be conditioned on parameters of the image, kind of how you can already scale the watermark based on the size of the image (indeed, afaik there’s no fixed size for the watermark). I don’t know how feasible that is though.

Again, frame color is something that you could easily do with G’MIC or Imagemagick but I guess you would like to do it within darktable. E.g., I don’t do watermarks in my PlayRaws but I sometimes frame them using the average color. Simple example:

gmic sample tiger frame 10,10,${-average_color}

Cool! Yeah, it’s clear that there are other tools where you can do it. I guess this would be a nice feature to have within darktable since it seems like a logical extension of the current feature set. But again, I have no idea how feasible this is given the current codebase.

You can adapt a lua script to call gmic and pass it whatever arguments you’d like. The exiftool script should be a good place to start: lua-scripts/exiftool_export.lua at exiftool · chrik5/lua-scripts · GitHub


Yeah, that sounds like a good idea. Thanks all for the helpful suggestions! I’m going to go do some coding soon so that the next time I want to export files, I won’t have to manually go through and set the watermark color :slightly_smiling_face: