Need to draw autofitted text that is..
Posted: 2012-12-28T13:34:47-07:00
Hi all. I need to draw text over background images. The width of the text needs to automatically fit in the width of the image as wide as possible while still having a small left/right margin.
I'm halfway there using labels, but I'm running into some problems with positioning. I need the text to be horizontally centered (left/right margin should be equal), but I need it to translate up or down along the y axis depending on my offset. So I can't use -gravity center.
Any help would be greatly appreciated.
Here is what I have now:
For example, with a 300x300 image
convert -background none -size 300x300 -fill 'black' label:"Test" test_label.png
convert bg.png -draw 'image over 6,60 0,0 "test_label.png"' out.png
The x, y are actually being determined programmatically by a Python script. I'm using the width of the image * 0.02 to determine X. This fails to center the text for most cases, and was only sufficient for the test case where the label is "Test"
Is there some way I can logically chain the commands? Say, start off with -gravity center and then translate the label up or down from there?
Again, any help would be greatly appreciated.
I'm halfway there using labels, but I'm running into some problems with positioning. I need the text to be horizontally centered (left/right margin should be equal), but I need it to translate up or down along the y axis depending on my offset. So I can't use -gravity center.
Any help would be greatly appreciated.
Here is what I have now:
For example, with a 300x300 image
convert -background none -size 300x300 -fill 'black' label:"Test" test_label.png
convert bg.png -draw 'image over 6,60 0,0 "test_label.png"' out.png
The x, y are actually being determined programmatically by a Python script. I'm using the width of the image * 0.02 to determine X. This fails to center the text for most cases, and was only sufficient for the test case where the label is "Test"
Is there some way I can logically chain the commands? Say, start off with -gravity center and then translate the label up or down from there?
Again, any help would be greatly appreciated.