Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
SET Option=-pointsize 100 -background "#00000000" -fill
convert %Option% white label:"Test" label.miff
FOR /F %%i in ('identify -format %%wx%%h Label.miff') DO ^
convert DSCN9046_r.JPG -gravity northeast -crop %%i+0+0 test.miff
FOR /F %%i IN ('Identify -format "%%[fx:mean]" test.miff') DO ^
IF %%i LEQ 0.5 (
SET Color=white
) Else (
SET Color=black
)
convert %option% !color! label:"Test" DSCN9046_r.JPG -reverse -compose over -gravity northeast -geometry +0+0 -composite DSCN9046_c.jpg
1) Generate an image with the label in white letters
2) Identify its size
3) Cut the according piece from the image that I want to label
4) Identify its mean value (fx gives values 0 -- 1)
5) If this value is less than 0.5 --> white letters, otherwise black letters
6) Do the actual labelling with the correct letter color.
Although the code works, I wonder if there is a more elegant solution to the problem, without creating so many temporal files.
One problem was that -gravity isn't available for Identify. And there seems to be no -identify option for Convert, such that I could try to create an interim result and use it in the same command line. Piping in Windows is limited to simple string values.