Results 1 to 2 of 2

Thread: imagettftext

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    imagettftext

    Hey,

    Ok I'm drawing some text onto an image using imagettftext, (The text is at an angle) and we have a fixed area the text can go into, the user can input between 1 and 25 characters. The more characters they put in the smaller the text needs to be. How can I get the character width of a ttf font at a certain size (and ideally per character because 'I' will be smaller than 'W')

    Thanks

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: imagettftext

    well, you could use imagefontwidth(); but you'll need to use it in conjunction with imageloadfont(), and you'll need a GDF font file, and you'll need to be using imagestring() rather than imagettftext() (and imagestring() does not support rotation as far as I recall)!

    but, if you want to stick with true type fonts, you could alternatively try using imagettfbbox() to create the bounding box of the text you're creating, and then scale it down depending on where that lands?

    edit: I was doing some testing, and imagefontwidth() will respond to a path to a TTF file. however, when using it on Arial, I got a return value of 5 (which could just be the maximum width of any character, though I have no idea what font size it was!); now, how useful this might be to you, I'm not sure. and I haven't even used it on another file so it could just not be returning correctly at all! I'm really not sure. either way, even the "solution" I gave you about that loads a font and uses imagestring() probably wouldn't be very useful at all. try the bounding box, maybe! /ramble-off.
    Last edited by kows; Oct 2nd, 2009 at 08:42 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width