Page 1 of 1
-draw centering text from absolute XY coords
Posted: 2011-11-11T09:16:48-07:00
by SamL
Dear Magicians..
I am pulling a set of xy coords from a database. These xy coords are supposed to be the center point from where text would become centered. I've tried every combination of gravity to accomplish this to no avail. Keep in mind, that the only coords that I have, are the CENTER POINT from where the text should be centered. Using the command below, I can get the text overlayed onto the image perfectly, beginning at the XY coords, but not centered from there:
Imagemagick command: /usr/bin/convert "/var/dgfiles/automate/incoming/aip4-test.jpg" -font "/var/dgfiles/automate/fonts/TitilliumText22L003.otf" -pointsize 38 -fill white -draw "text 435,524 \"Apocalypse Blue\"'" -font "/var/dgfiles/automate/fonts/TitilliumText22L003.otf" -pointsize 27 -fill white -draw "text 435,560 'by Girsl Collective'" -font "/var/dgfiles/automate/fonts/Museo_Slab_500.otf" -pointsize 58 -fill white -draw "text 435,1023 'F66981DFAIP4'" "/var/dgfiles/automate/outgoing/aoc-test.jpg"
ANY TIPS would be hugely appreciated.
Thank you,
Sam
Re: -draw centering text from absolute XY coords
Posted: 2011-11-11T10:44:45-07:00
by fmw42
Use -annotate. Something like this seems to work for me on IM 6.7.3.5 Q16 Mac OSX Tiger
x=150
y=150
w=200
h=200
ox=`convert xc: -format "%[fx:$x-$w/2]" info:`
oy=`convert xc: -format "%[fx:$y-$h/2]" info:`
convert -size ${w}x${h} xc:white -gravity center -font Arial -pointsize 12 \
-annotate +$ox+$oy "TESTING" tmp.png
The issue will be that you will need to compute the sign for ox and oy as IM does not work when you do +-10+-10, nor will it work if you do $ox$oy because it needs a sign and you wont get a + sign from the variables. So compute the sign and absolute value for ox and oy and create your offsets to -annotate appropriately with the proper sign such as +10-10.
If you need further help on this, let me know as I have done that before.
Re: -draw centering text from absolute XY coords
Posted: 2011-11-11T12:18:15-07:00
by SamL
Are you saying the only way this can work is if i know the size of the area the text is supposed to be placed within??
Re: -draw centering text from absolute XY coords
Posted: 2011-11-11T13:00:01-07:00
by fmw42
SamL wrote:Are you saying the only way this can work is if i know the size of the area the text is supposed to be placed within??
I think so. But I will defer to the IM developers. Perhaps there is some way that I do not know about.
Re: -draw centering text from absolute XY coords
Posted: 2011-11-12T19:16:11-07:00
by SamL
I think I might be getting somewhere but am not really sure...
This command produces text at the center of the image as expected:
/usr/bin/convert "/var/dgfiles/automate/incoming/aip4-test.jpg" -font "/var/dgfiles/automate/fonts/TitilliumText22L003.otf" -pointsize 38 -fill White -gravity Center -draw "text 0,0 'Apocalypse Blue'" "/var/dgfiles/automate/outgoing/aoc-test.jpg"
However, when I try to apply a region to the command, I no longer see the text...
/usr/bin/convert "/var/dgfiles/automate/incoming/aip4-test.jpg" -font "/var/dgfiles/automate/fonts/TitilliumText22L003.otf" -pointsize 38 -fill White -gravity Center -region 489x42+190+502 -draw "text 0,0 'Apocalypse Blue'" "/var/dgfiles/automate/outgoing/aoc-test.jpg"
My thought was that I could create a 'region' then somehow place the text in the center of that region?
Is that possible?
Thank you,
Sam
Re: -draw centering text from absolute XY coords
Posted: 2011-11-13T02:17:05-07:00
by Bonzo
Another idea may be to create a label and put the label on the image:
Code: Select all
convert -background none -fill blue -pointsize 70 label:Anthony miff:- | composite - london.png -gravity center -geometry +100+100 output.jpg
convert london.png ( -background none -fill blue -pointsize 70 label:Anthony ) -gravity center -geometry +100+100 -composite output.jpg
Re: -draw centering text from absolute XY coords
Posted: 2011-11-13T22:38:37-07:00
by anthony
SamL wrote:Are you saying the only way this can work is if i know the size of the area the text is supposed to be placed within??
At this time yes. The separation of text (and image) justification, from the gravity positioning setting is something that will be looked at early is IMv7 development. We are currently only in alpha at this time.