Page 1 of 1

Watermark color depending on the background

Posted: 2019-03-23T01:13:21-07:00
by AKapaceb
Hello Friends!

Help me with command...

How can determine the color of a particular selected area in the picture, so that later i can insert a watermark depending on the background color. If the color background is light, then insert a black watermark. Or if the background color is black, then insert the lighter!

Some examples:
Image
Image
Image

Thank you so much! :)

Re: Watermark color depending on the background

Posted: 2019-03-23T03:30:03-07:00
by snibgo
What version of IM, on what platform?

The basic idea is to crop the desired rectangle, and find the average lightness. If this is less than 50% (or whatever threshold you want) the text will be white, otherwise black.

With v7 this can probably be done in one command. In v6 it will need a shell script.

Re: Watermark color depending on the background

Posted: 2019-03-23T03:35:47-07:00
by AKapaceb
Image
Debian 8

Re: Watermark color depending on the background

Posted: 2019-03-23T04:49:58-07:00
by snibgo
For example, bash syntax:

Code: Select all

PERCENT=$(convert \
  toes.png \
  -gravity East \
  -crop 40x200+0+0 +repage \
  -format "%[fx:mean<0.5?100:0]" \
  info:)
For the fill in the command that annotates or labels the image, use:

Code: Select all

-fill "gray($PERCENT%)"