Jump to content

GD Text to Image


CanMan2004

Recommended Posts

Hi all

I have a simple text to image GD script

[code]<?php
header ("Content-type: image/png");
$handle = ImageCreate (275, 386) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 255, 255, 255);
$txt_color = ImageColorAllocate ($handle, 0, 0, 0);
ImageTTFText ($handle, 8, 180, 270, 360, $txt_color, "arial.ttf", "".$_GET['txt']."");
ImagePng ($handle);
?>[/code]

It works when passing the URL

www.mysite.com/website/image.php?txt=this is a test

The script works fine, my question is, how can I get the text to word wrap, as it currently keeps all text onto the same line.

Secondly, how can I get GD to understand line breaks in the url, for example, if I pass the text

this is a text<br>this is another test<br>this is the last test

then it shows all that on one line, and prints in the text <br>

that is the same if you replace <br> with \n

Any help would be great

Thanks in advance

Ed
Link to comment
Share on other sites

i only have simple knowledge of the gd library, just enough to do a little customization of captcha type scripts, but i don't think the gd library specifically supports that. I think you are going to have to write your own function with conditions and some regexing and then create the image with the text using specific x,y coordinates, based on # of lines, etc... but hey, i could be wrong. there might be some gd function already made that does all that for you. 
Link to comment
Share on other sites

gd alone can't do what you want.

Pass the multi-line text using an obvious delimiter between lines.
At the start of your gd script, use the explode() function to separate that multi-line text into single lines.
The size of the exploded array will let you define the vertical co-ordinate for each separate line
Loop thru' theImageTTFtext as many times as you have separate lines
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.