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
-draw centering text from absolute XY coords
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: -draw centering text from absolute XY coords
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.
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
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??
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: -draw centering text from absolute XY coords
I think so. But I will defer to the IM developers. Perhaps there is some way that I do not know about.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??
Re: -draw centering text from absolute XY coords
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
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
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
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: -draw centering text from absolute XY coords
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.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??
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/