Placen a text over a image
Placen a text over a image
Hello:
I wonder what will be the simplest way to
add a text over a image.
Lets say I want to add «This is my cat»
on the bottom center of the image.
I really would like to make the text transparent
so it would integrate much better with the image
But since the image on that place could be of any color
if I make the text White, then sometimes I could not see it.
I remember that one way to solve this was tha the letter
woud have 2 colors, so at lest one of them
would be seen.
Maybe IM solves this issue in another way.
Also the other problema is how to place the image
on a certain possition regardless of its size.
Thanks
Emilio
I
I wonder what will be the simplest way to
add a text over a image.
Lets say I want to add «This is my cat»
on the bottom center of the image.
I really would like to make the text transparent
so it would integrate much better with the image
But since the image on that place could be of any color
if I make the text White, then sometimes I could not see it.
I remember that one way to solve this was tha the letter
woud have 2 colors, so at lest one of them
would be seen.
Maybe IM solves this issue in another way.
Also the other problema is how to place the image
on a certain possition regardless of its size.
Thanks
Emilio
I
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Placen a text over a image
snibgo's IM pages: im.snibgo.com
- 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
IM does not support two color text that would automatically use say black where the image is light and white where the image is dark.
However, this could be scripted by creating both white and black text on a transparent background. Then make a mask the identifies whether the image under each letter is brighter or darker than mid gray. Then composite the two text images according to the mask. Then compose the composite text image over the image.
For positioning, you can use -gravity and -geometry when compositing. -annotate allow -gravity and has offset arguments.
However, this could be scripted by creating both white and black text on a transparent background. Then make a mask the identifies whether the image under each letter is brighter or darker than mid gray. Then composite the two text images according to the mask. Then compose the composite text image over the image.
For positioning, you can use -gravity and -geometry when compositing. -annotate allow -gravity and has offset arguments.
Re: Placen a text over a image
snibgo and fmw42:
I got using IM to place a text on top a images, no problem.
Still I got the problem of the color of the text on top of a similar color on the image.
And I will try to learn how to do it using fmw42 suggestion.
At the momento I have a problem of choosing colors in the -fill ( i got while, black, red, blue) is there a list
of the usable colors... I have not been able to finf it.
Thanks
Emilio
I got using IM to place a text on top a images, no problem.
Still I got the problem of the color of the text on top of a similar color on the image.
And I will try to learn how to do it using fmw42 suggestion.
At the momento I have a problem of choosing colors in the -fill ( i got while, black, red, blue) is there a list
of the usable colors... I have not been able to finf it.
Thanks
Emilio
Re: Placen a text over a image
I believe the user whugemann wrote some code to set the background colour light or dark depending on the background colour. You could search his posts and see if you can find it. At a guess it was four or more years ago.
To find the colours available:
To find the colours available:
Code: Select all
convert -list color
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Placen a text over a image
is there a list of the usable colors... I have not been able to finf it.
Code: Select all
convert -list color
snibgo's IM pages: im.snibgo.com
- 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
Here is a simple example using a gradient as background.
Here is another with a checkerboard background.
You can also do it perhaps simpler using -annotate rather than label:, or caption: if you needed multi-line text
But you may need to blur the image under the text. As you can see in the checkerboard example, it is harder to read when each letter may be broken up into white and black parts.
Personally, I think that unless you have slowly varying background colors, you may be better off with an undercolor as background to the text and then put that over your image.
Code: Select all
convert -respect-parenthesis \( -size 200x200 gradient: -rotate 90 \) \
\( -clone 0 -background none -pointsize 36 -font arial -fill white label:"Testing" \
-gravity center -compose over -composite \) \
\( -clone 0 -background none -pointsize 36 -font arial -fill black label:"Testing" \
-gravity center -compose over -composite \) \
\( -clone 0 -threshold 50% \) \
-delete 0 -compose over -composite contrast_text.jpg
Here is another with a checkerboard background.
Code: Select all
convert -respect-parenthesis \( -size 60x60 pattern:checkerboard -resize 200x200 \) \
\( -clone 0 -background none -pointsize 36 -font arial -fill white label:"Testing" \
-gravity center -compose over -composite \) \
\( -clone 0 -background none -pointsize 36 -font arial -fill black label:"Testing" \
-gravity center -compose over -composite \) \
\( -clone 0 -threshold 50% \) \
-delete 0 -compose over -composite contrast_text2.jpg
You can also do it perhaps simpler using -annotate rather than label:, or caption: if you needed multi-line text
But you may need to blur the image under the text. As you can see in the checkerboard example, it is harder to read when each letter may be broken up into white and black parts.
Personally, I think that unless you have slowly varying background colors, you may be better off with an undercolor as background to the text and then put that over your image.
Re: Placen a text over a image
bonzo and snibgo:
Thanks the "-list color" is what I needed.
bonzo:
Yes I found the message from whugemann
Re: Labelling in either black or White
That is the idea... but at the momento toooooo complex for me
fmw42:
I reproduced your first Testing Gradient... most impresive.
"Personally, I think that unless you have slowly varying background colors, you may be better off with an undercolor as background to the text and then put that over your image"
I completelly agree with this statement, and is one of the systems I have been using. I put a rectangle, with a black background and a White text.
But.... it is not as elegant as transparent text over a image.
Still how do I make the text placed on a image to have a rectangle around it with a given color?
Thanks to all
Emilio
Thanks the "-list color" is what I needed.
bonzo:
Yes I found the message from whugemann
Re: Labelling in either black or White
That is the idea... but at the momento toooooo complex for me
fmw42:
I reproduced your first Testing Gradient... most impresive.
"Personally, I think that unless you have slowly varying background colors, you may be better off with an undercolor as background to the text and then put that over your image"
I completelly agree with this statement, and is one of the systems I have been using. I put a rectangle, with a black background and a White text.
But.... it is not as elegant as transparent text over a image.
Still how do I make the text placed on a image to have a rectangle around it with a given color?
Thanks to all
Emilio
Re: Placen a text over a image
You do not say how you are using the code but here is whugemann's code in php.
I have also had to input an if statement in as I am having a problem getting the %%j00%% part to work
I have also had to input an if statement in as I am having a problem getting the %%j00%% part to work
Code: Select all
$image="in.jpg";
$gravity="-gravity center";
$Option="-pointsize 100 -background \"#00000000\" -fill";
// Create the label and get the size for calculating the averidge background colour
$data = exec("convert $Option white label:\"Test\" -format %wx%h info:");
// Crop the background and find the averidge colour - light and the text is black otherwise the colour is white
$background = exec("convert $image $gravity -crop $data+0+0 -format \"%[fx:(mean<0.5)?1:0]\" info:");
// Write the colour onto the image with the correct colour
if ( $background == 0 ) { $text = "0,0,0";}
else $text = "256,256,256";
$cmd = " $Option rgba\($text,0.5\) label:\"Test\" $image -reverse -compose over $gravity -geometry +0+0 -composite ";
exec("convert $cmd c_image.jpg");
- 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
It depends upon what command you are using.Still how do I make the text placed on a image to have a rectangle around it with a given color?
If label: then you must use a background color other than none (-background somecolor) and then compose the result of label: over your background image.
If -annotate, then you just add -undercolor somecolor and apply the command to your background image.
See
http://www.imagemagick.org/Usage/text
http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/Usage/layers/#convert
Re: Placen a text over a image
bonzo:
I am using wWindows, and basically to activate the IM code I use
RUN convert.....
I do not know PHP, which looks like it is a great language but above my posibilities.
Sorry not to be able to use your code.
fmw42
I have used your code and it works.
run "convert foto.jpg -fill "#123" -stroke black -font Arial -pointsize 100 -gravity south -annotate 0 "Hola" annotate_rose.jpg"
But if I try to use your suggestion no image is create
run "convert foto.jpg -fill "#123" -stroke black -font Arial -pointsize 100 -gravity south -annotate 0 -undercolor blue "Hola" annotate_rose.jpg"
Also I have tried with label, with the same result.
I feel I am not placing the suggestions in the proper place.
Emilio
I am using wWindows, and basically to activate the IM code I use
RUN convert.....
I do not know PHP, which looks like it is a great language but above my posibilities.
Sorry not to be able to use your code.
fmw42
I have used your code and it works.
run "convert foto.jpg -fill "#123" -stroke black -font Arial -pointsize 100 -gravity south -annotate 0 "Hola" annotate_rose.jpg"
But if I try to use your suggestion no image is create
run "convert foto.jpg -fill "#123" -stroke black -font Arial -pointsize 100 -gravity south -annotate 0 -undercolor blue "Hola" annotate_rose.jpg"
Also I have tried with label, with the same result.
I feel I am not placing the suggestions in the proper place.
Emilio
Re: Placen a text over a image
whugemann's code is a batch file; save the below and drop an image over it for the watermark.
Currently saves as a jpg and the text does not have transparency.
Currently saves as a jpg and the text does not have transparency.
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 %1 %gravity% -crop %%i+0+0 -format "%%[fx:(mean<0.5)?1:0]" info:') DO ^
convert %Option% rgb(%%j00%%,%%j00%%,%%j00%%) label:"Test" %1 -reverse -compose over %gravity% -geometry +0+0 -composite "th_%~n1.jpg"
- 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
try putting undercolor before -annotate
Code: Select all
convert foto.jpg -fill "#123" -stroke black -font Arial -pointsize 100 -gravity south -undercolor blue -annotate +0+0 "Hola" annotate_rose.jpg
Re: Placen a text over a image
Bonzo:
I feel you got a very bad student
But I try hard.
I have tried to activate your code which I made it as a .bat = text1.bat
I got this error.
C:\GEST03B10>FOR /F %j IN ('convert -gravity Center -crop 184x113+0+0 -format "%
[fx:(mean<0.5)?1:0]" info:') DO convert -pointsize 100 -background "#00000000" -
fill rgb(%j00%,%j00%,%j00%) label:"Test" -reverse -compose over -gravity Cente
r -geometry +0+0 -composite "th_.jpg"
convert.exe: no images defined `info:' @ error/convert.c/ConvertImageCommand/318
7.
So since the error states that no images are defined, I place one in text2.bat and 2 in text3.bat
The result is the same.
I feel the code you placed I have to modify it somehow, maybe wordrap or the DO in another line.
Sorry I am not to good at this.
Thanks for your help.
Really the fact you state that your code will make the text NOT transparent would be great.
fmw42:
Yes that is perfect, now I have 2 options to offer the users.
1) Elegant (transparent) BUT not always visible
2) Very readable BUT not elegant.
Y wish I get Bonzo's solution to offer the best of the 2 worlds
Thanks both of you for the help.
Emilio
I feel you got a very bad student
But I try hard.
I have tried to activate your code which I made it as a .bat = text1.bat
I got this error.
C:\GEST03B10>FOR /F %j IN ('convert -gravity Center -crop 184x113+0+0 -format "%
[fx:(mean<0.5)?1:0]" info:') DO convert -pointsize 100 -background "#00000000" -
fill rgb(%j00%,%j00%,%j00%) label:"Test" -reverse -compose over -gravity Cente
r -geometry +0+0 -composite "th_.jpg"
convert.exe: no images defined `info:' @ error/convert.c/ConvertImageCommand/318
7.
So since the error states that no images are defined, I place one in text2.bat and 2 in text3.bat
The result is the same.
I feel the code you placed I have to modify it somehow, maybe wordrap or the DO in another line.
Sorry I am not to good at this.
Thanks for your help.
Really the fact you state that your code will make the text NOT transparent would be great.
fmw42:
Yes that is perfect, now I have 2 options to offer the users.
1) Elegant (transparent) BUT not always visible
2) Very readable BUT not elegant.
Y wish I get Bonzo's solution to offer the best of the 2 worlds
Thanks both of you for the help.
Emilio