Apologies -- I just noticed that at the end of the message below which I recently posted, I said "the length of "This is my Text" in inches, when printed in Helvetica-Bold in point-size 15."
That was incorrect, since everything preceding was done in terms of Courier-Bold!
To see what it comes to in terms of Helvetica-Bold, substitute "HB" for "CB" in the commands. Thus:
echo "\f[HB]\w'This is my Text'\s0\fP" | troff -Tps | awk '/^t/{sub(/t/,""); print $0/72000}'
results in
0.988889
the length in inches of "This is my Text" in Helvetica-Bold in the default point-size of 10 points, while
echo "\f[HB]\w'\s[15]This is my Text'\s0\fP" | troff -Tps | awk '/^t/{sub(/t/,""); print $0/72000}'
results in
1.48333
the length in inches of "This is my Text" in Helvetica-Bold in 15-point (1.5 times as long as in 10-point).
Also note (which I forgot to mention) that this length takes account of kerning (the slight left-shift of some letters relative to a preceding letter -- e.g. in "Text" the "ext" is moved left so tht the "e" is slightly overlapped by the preceding "T"). Kerning can be suppressed. Also, of course, the length is computed in terms of the font-metrics in the font files referred to by troff, and in other applications different font files may be used; however, the result is unlikely to be greatly different.
Sorry for the sloppiness! Ted.
-----FW: XFMail.091201122319.Ted.Harding@manchester.ac.uk-----
Date: Tue, 01 Dec 2009 12:23:19 -0000 (GMT) Sender: main-bounces@lists.alug.org.uk From: (Ted Harding) Ted.Harding@manchester.ac.uk To: main@lists.alug.org.uk Subject: Re: [ALUG] Using ImageMagick to overlay text
On 01-Dec-09 09:06:14, Mark Rogers wrote:
MJ Ray wrote:
I'd either run identify on the image beforehand, or test PHP's libgd module to see if it was good enough for this.
I will try GD today and see what the results are like (the results from ImageMagick are pretty amazing, to be honest).
I'm not sure what you mean about using identify though - I can see how I'd use it to work out the size of the image but I can't see how I'd use > that information to calculate the pointsize to use with my text?
-- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251
Your basic problem here is to find the printed length of a given text string, in a given font, at a given point size!
You could incorporate something like the following in a script:
echo "\f[CB]\w'This is my Text'\fP" | troff -Tps
from which the output (to screen, when I entered the above on the command line) is;
x T ps x res 72000 1 1 x init C p1 x font 6 CB f6 s10000 V12000 H72000 md DFd t90000 n12000 0 x trailer V792000 x stop
The key line in there is t90000 which is the evaluation of the width ("\w'...'")of the string "This is my Text" in point-size 10 (the default) using font Courier-Bold ("\f[CB]"). The numerical result "90000" is the length of the text in units of (1 point)/1000, i.e. 1/72000 of an inch, so the physical printed length would be
90000/72000 = 1.25 inches
You could feed that to 'awk' to do the sums (and this time I'll feed in an explicit point-size 15 ("\s[15]...\s0") as well):
echo "\f[CB]\s[15]\w'This is my Text'\s0\fP" | troff -Tps | awk '/^t'/
results in:
t135000
while
echo "\f[CB]\s[15]\w'This is my Text'\s0\fP" | troff -Tps | awk '/^t/{sub(/t/,""); print $0}'
results in
135000
so, finally,
echo "\f[CB]\w'\s[15]This is my Text'\s0\fP" | troff -Tps | awk '/^t/{sub(/t/,""); print $0/72000}'
results in
1.875
which is (15/10)*1.25, the length of "This is my Text" in inches, when printed in Helvetica-Bold in point-size 15. There may be some discrepancy, depending on how spaces are handled in the output.
You can probably exploit the above ideas to get what you want! Hoping this helps, Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 01-Dec-09 Time: 12:23:16 ------------------------------ XFMail ------------------------------
_______________________________________________ main@lists.alug.org.uk http://www.alug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!
--------------End of forwarded message-------------------------
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 01-Dec-09 Time: 14:22:46 ------------------------------ XFMail ------------------------------