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 ------------------------------