Page 3 of 3
Re: Placen a text over a image
Posted: 2015-09-22T09:06:59-07:00
by fmw42
As I said above, in my opinion, this code should not create the shown result, since it only measures the mean of the whole subsection. Perhaps I have misunderstood something.
Bonzo or snibgo, does his code work for you to produce his result on his image? If so, can you explain what I am missing about it.
Re: Placen a text over a image
Posted: 2015-09-22T09:35:42-07:00
by snibgo
I don't know what the OP wants as a final result. The code doesn't seem to do anything useful.
Code: Select all
FOR /F %%i IN ('convert %Option% white label:"Test" -format %%wx%%h info:') DO ^
FOR /F %%j IN ('convert foto.jpg %gravity% -crop %%i+0+0 -format "%%[fx:(mean<0.5)?1:0]" info:') DO ^
convert foto.jpg %Option% rgb(%%j00%%,%%j00%%,%%j00%%) label:"Molinos del Quijote" %1 -reverse -compose over %gravity% -geometry +0+0 -composite "_xxxx1111.jpg"
Perhaps the desired result has the text placed over the image. But the final convert has "-reverse", so places the image over the text, cropped down to the size of the text. So the result has a crop of the windmills, with no text. If we remove "-reverse", we get white text over the windmills:
Code: Select all
FOR /F %%i IN ('convert %Option% white label:"Test" -format %%wx%%h info:') DO ^
FOR /F %%j IN ('convert foto.jpg %gravity% -crop %%i+0+0 -format "%%[fx:(mean<0.5)?1:0]" info:') DO ^
convert foto.jpg %Option% rgb(%%j00%%,%%j00%%,%%j00%%) label:"Molinos del Quijote" %1 -compose over %gravity% -geometry +0+0 -composite "_xxxx1111.jpg"
If the image is lighter, the text is made black instead of white. We can test this by adjusting the gamma in the middle convert:
Code: Select all
FOR /F %%i IN ('convert %Option% white label:"Test" -format %%wx%%h info:') DO ^
FOR /F %%j IN ('convert foto.jpg -gamma 3 %gravity% -crop %%i+0+0 -format "%%[fx:(mean<0.5)?1:0]" info:') DO ^
convert foto.jpg %Option% rgb(%%j00%%,%%j00%%,%%j00%%) label:"Molinos del Quijote" %1 -compose over %gravity% -geometry +0+0 -composite "_xxxx1111.jpg"
I don't know why two different text strings are used. With the short "Test", only a small portion of the image is tested for the mean value.
Re: Placen a text over a image
Posted: 2015-09-22T10:10:16-07:00
by fmw42
snibgo
This was the code I was looking at:
viewtopic.php?f=1&t=28377#p126012 (from Bonzo)
This is the OP example result:
viewtopic.php?f=1&t=28377&start=15#p126036
My equivalent code only made black text over a gradient image:
viewtopic.php?f=1&t=28377&start=15#p126042
Re: Placen a text over a image
Posted: 2015-09-22T10:43:51-07:00
by snibgo
That code from Bonzo works fine. Changing "%1" to "foto.jpg":
Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
SET gravity=-gravity Center
SET Option=-pointsize 100 -background "#00000000" -fill
FOR /F %%i IN ('convert %Option% white label:"Test" -format %%wx%%h info:') DO ^
FOR /F %%j IN ('convert foto.jpg %gravity% -crop %%i+0+0 -format "%%[fx:(mean<0.5)?1:0]" info:') DO ^
convert %Option% rgb(%%j00%%,%%j00%%,%%j00%%) label:"Test" foto.jpg -reverse -compose over %gravity% -geometry +0+0 -composite "t.jpg"
The result has text over the windmills. The text is opaque white. If the image was lighter, the text would be opaque black.
Many schemes for making text legible over images are possible, such as white text with black outline, white text with black shadow, white text over black blurred text, white text over opaque black rectangle, or white text over semi-transparent black rectangle.
Or the text colour can vary, so each text pixel may be different. This reduces legibility, and makes the text seem more integrated with the image.
Re: Placen a text over a image
Posted: 2015-09-22T10:47:57-07:00
by fmw42
snibgo,
My point was that this code cannot produce a result such as the OP posted in his link to his resulting image with the black windmill covering the white text such that it looks as if the white text is behind the windmill. I agree that the code should produce solid white text over the image. Thanks for confirming my suspicion that he must be using some other code to produce a result such as he showed in his image.
Re: Placen a text over a image
Posted: 2015-09-22T11:26:29-07:00
by Bonzo
As I understood the original question the OP wanted a dark text over a light image and a light text over a dark Image
The code I modified and posted was from a post about 5 years ago by whugemann
The image of the windmill posted by the op was created using that code although it looks as though the text is now transparent rather than solid. Perhaps he used rgba as I suggested in another post.
A crop of the text showing the windmill behind the text:

Re: Placen a text over a image
Posted: 2015-09-22T11:48:45-07:00
by fmw42
Bonzo,
I think with rgba, it shows half transparent white text over the image. So it blends with either blue or black. It is not
fully transparent where the image is black as in my example. At full resolution, compare my example at
viewtopic.php?f=1&t=28377&start=15#p126049. My result is in the upper left corner and his is in the middle.