Placen a text over a image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Placen a text over a image

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Placen a text over a image

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Placen a text over a image

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Placen a text over a image

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Placen a text over a image

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Placen a text over a image

Post 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:

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Placen a text over a image

Post 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.
Post Reply