Image Magic align text points based on number of text points
Is it possible to get somehow the width of a text which one draws in image magick?
My current convert command looks like this:
convert -size 720x480 -background #000 xc:black -fill white -stroke white -font Arial -pointsize 18 -draw "text 72,370 'NavP1'" -font Arial -pointsize 18 -draw "text , ''" -font Arial -pointsize 18 -draw "text , ''" -font Arial -pointsize 18 -draw "text 370,370 'Extras'" -font Arial -pointsize 18 -draw "text 430,370 'opt'" -font Arial -pointsize 18 -draw "text 550,370 'NavP1'" C:xampphtdocslabelText.bmp
I did this programmatically and want to center and align the navigation points to each other based on how many navigation points I have
( I get the number of navigation points from my php formular / database ).
Here is a little sketch of what I mean and how it should look like
________________________________________
| |
| |
| |
| navp1 navp2 |
|_______________________________________|
________________________________________
| |
| |
| |
| navp1 navp2 navp3 |
|_______________________________________|
I have a fixed width for that image (720px).
Thus I have a minimum number of 2 navigation points and a maximum number of 6 navigation points.
My thought is that if I could get the width of each Navigation (text/word) point I could calculate and align the points correctly.
But right know I could not find a function which does that.
I tried Mark Setchell Answer but my command seems to have a mistake
convert -debug annotate -size 720x480 -background #000 xc:black -fill white -stroke white -font Arial -pointsize 18 -draw "text 72,370 'nav1'" -font Arial -pointsize 18 -draw "text 180,370 'nav2'" -font Arial -pointsize 18 -draw "text 430,370 'nav3'" -font Arial -pointsize 18 -draw "text 550,370 'nav4'" C:xampphtdocstest.bmp
but I get following error message:
no images defined '-background' @ error/convert.c/ConvertImageCommand/325
I am not sure I fully understand what you are looking for, but I think that getting the font metrics will maybe help. Try this and look for all the numbers you want in the line commencing "Metrics:":
convert -debug annotate -size 720x480 -background red xc:black -fill white -stroke white -font Arial -pointsize 18 -draw "text 82,370 'Nav P1'" a.png
Output
2016-06-03T09:50:12+01:00 0:00.010 0.010u 6.9.4 Annotate convert[85474]: annotate.c/RenderFreetype/1421/Annotate
Font /Library/Fonts/Arial.ttf; font-encoding none; text-encoding none; pointsize 18
2016-06-03T09:50:12+01:00 0:00.020 0.010u 6.9.4 Annotate convert[85474]: annotate.c/GetTypeMetrics/843/Annotate
Metrics: text: Nav P1; width: 58; height: 21; ascent: 16; descent: -4; max advance: 36; bounds: 1.95312,0 6.70312,14; origin: 59,0; pixels per em: 18,18; underline position: -4.5625; underline thickness: 2.34375
2016-06-03T09:50:12+01:00 0:00.020 0.010u 6.9.4 Annotate convert[85474]: annotate.c/RenderFreetype/1421/Annotate
Font /Library/Fonts/Arial.ttf; font-encoding none; text-encoding none; pointsize 18
链接地址: http://www.djcxy.com/p/90922.html