Controlling the size of overlayed text
Posted: 2009-12-01T05:02:42-07:00
I need to overlay some text over an image, and currently have this working:
The original image is quite large (3400x1020) and using pointsize 400 means my text covers 100% of the width. The final -resize will vary depending on usage (the final result will not resize at all, but intermediate results are resized for quick proofing of results).
What I want to do is have pointsize calculated automatically so that I can specify the text size as a percentage of the total image size (or I'm happy stating it in pixels relative to the original image). In other words, what I'd like to do is something like this:
or
but -size doesn't work that way. What is the correct way to do this?
What if I wanted to do 80% instead of 100%?
If I want instead to start by defining a bounding box for the text over the image, then let the text be scaled to fit within that box (with gravity applied as necessary), what is the best way then?
Code: Select all
convert infile.png -font font.ttf -gravity south \
-stroke "#000C" -strokewidth 3 -pointsize 400 \
-annotate 0 "Welcome to my world" \
-resize 1024x768 outfile.png
What I want to do is have pointsize calculated automatically so that I can specify the text size as a percentage of the total image size (or I'm happy stating it in pixels relative to the original image). In other words, what I'd like to do is something like this:
Code: Select all
#This doesn't work!
convert infile.png -font font.ttf -gravity south \
-stroke "#000C" -strokewidth 3 -size 3400x1020 \
-annotate 0 "Welcome to my world" \
-resize 1024x768 outfile.png
Code: Select all
#This doesn't work either!
convert infile.png -font font.ttf -gravity south \
-stroke "#000C" -strokewidth 3 -size 100% \
-annotate 0 "Welcome to my world" \
-resize 1024x768 outfile.png
What if I wanted to do 80% instead of 100%?
If I want instead to start by defining a bounding box for the text over the image, then let the text be scaled to fit within that box (with gravity applied as necessary), what is the best way then?