I'm new on this forum and french, so sorry for my english...
So I want to write some text, relative to a certain pont, on an image, with the baseline of the text. I have found a solution but there is maybe a better one.
Here it is :
For the example, I write "jabp" to see the baseline, on an image 400x300, relative to the point 250,180. Let's see the point :
Code: Select all
convert -size 400x300 pattern:checkerboard -stroke rgba(0,0,255,.8) -draw "line 0,180 400,180" -draw "line 250,0 250,300" croix.png
If I write text with "simple" position (-annotate +250+180), I wil have text written at the correct place, and justified on the left :
Code: Select all
convert -size 400x300 pattern:checkerboard -stroke rgba(0,0,255,.8) -draw "line 0,180 400,180" -draw "line 250,0 250,300" -fill rgba(255,255,255,.6) -stroke none -pointsize 50 -annotate +250+180 jabp just_left.png
Now come the problems : I want to write centered or right justified... My solution is to get the metrics informations of the text box :
Code: Select all
convert xc: -pointsize 50 -debug annotate -annotate 0 japb null:
Working in PHP, I found the "Metrics line", and then the width (95.2969). So for centered text for example, I just have to subtract the half of the width result (95.2969 / 2 ~= 47 ) to the "X" (250) annotate position (250 - 47 = 3) :2010-12-09T11:36:04+01:00 0:01 0.031u 6.5.6 Annotate convert[304]: annotate.c/RenderFreetype/1138/Annotate
Font c:\windows\fonts\arial.ttf; font-encoding none; text-encoding none; pointsize 50
2010-12-09T11:36:04+01:00 0:01 0.031u 6.5.6 Annotate convert[304]: annotate.c/GetTypeMetrics/732/Annotate
Metrics: text: japb; width: 95.2969; height: 58; ascent: 46; descent: -11; max advance: 100; bounds: -2.2968 8,-10 26,36; origin: 94,0; pixels per em: 50,50; underline position: -3.39063; underline thickness: 2.34375
2010-12-09T11:36:04+01:00 0:01 0.031u 6.5.6 Annotate convert[304]: annotate.c/RenderFreetype/1138/Annotate
Font c:\windows\fonts\arial.ttf; font-encoding none; text-encoding none; pointsize 50
Code: Select all
convert -size 400x300 pattern:checkerboard -stroke rgba(0,0,255,.8) -draw "line 0,180 400,180" -draw "line 250,0 250,300" -fill rgba(255,255,255,.6) -stroke none -pointsize 50 -annotate +203+180 jabp just_center.png
I didn't find a solution using -gravity option (it takes the whole text box, and not relative to the baseline of the text). So if somebody have a better solution, preferably without using -debug ...
thanks