Hi Monks, have a question that I'm not sure can be answered easily. I'd like to be able to figure out the length of a string by pixels. I know this is a very hard question because there are a lot of parameters that come into play, like which font, OS, browser, blah, blah... But I'm trying to get at a more general answer. I'd like to be able to find out the length of the word WAS is greater in length, because of W usually being the largest font character, than was. So, it'd be great to have a function that would tell me 'WAS' is 20 pixels and 'was' is 15 pixels.

I did find a post while googling showing a person that tried it through a gimp module. But not sure if that's the best way, I've never even used the Gimp before.

Thanks in advance Monks...

UPDATE:Sorry Monks, I didn't explain why I needed this. I am creating pdf's and I need to calculate space for a certain part of a pdf document I am creating. So, the calculation by pixels will tell me how far I can go with the text, where the left position can start, and if I have to split the line into smaller parts. Thanks again.

In reply to Font size by pixels. by the_0ne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.