Image Functions

Discussion in 'PHP' started by Danago, Dec 25, 2006.

  1. #1
    Hi. Lets say i create an image using php, with the dimentions 250x100px. How can i then write a string onto that image, which will break into new lines, to fit onto it? Using the imagestring() function, it seems to just continue, past the edge of the image.

    Thanks in advance,
    Dan.
     
    Danago, Dec 25, 2006 IP
  2. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #2
    i think the image functions dont support this feature, but wordwrap() may be usefull for you - breaks the text to a new line after x chars.
     
    falcondriver, Dec 26, 2006 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    You can add two or more image strings to it. Wordwrap won't work, neither the new line character \n.
     
    nico_swd, Dec 26, 2006 IP
  4. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #4
    what? you cant wordwrap() your text and then insert it into the image?! never tried it, but thats kinda lame :/
     
    falcondriver, Dec 26, 2006 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    The only method I came across to insert multiple text lines into an image is using the imagestring() fuction twice or more. If anyone has another solution, feel free to share.
     
    nico_swd, Dec 26, 2006 IP
  6. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I would say use some function to determine how many rows there would be when the text is properly placed on the image. For example if you can put 50 characters in one line and the text has 150 characters, you'd need 3 lines.
    Then you set different starting positions for the situations if you have only 1 line, if you have 2 lines etc. up to whatever maximum amount of lines you'd like to use.
    When you have done that you simply break the text into rows and voilá.
     
    Icheb, Dec 26, 2006 IP
  7. pixel_perfect

    pixel_perfect Banned

    Messages:
    238
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ok, I can help you! whats the deal? I have played with image and wrapping things... alot!
     
    pixel_perfect, Dec 26, 2006 IP
  8. Danago

    Danago Active Member

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #8
    Hmm ok thanks for the replies everyone. Guess ill just have to make my own function then.
     
    Danago, Dec 27, 2006 IP