Jump to content

Recommended Posts

Posted

Hey gang,

 

I am using a script to display random sigs at the bottom of my posts. The problem is that it only allows one line. Is there a change I can make to allow for word wrap so I can use a larger font or more text?

 

Here is the script.

 

><?php
$font_file = $_SERVER[DOCUMENT_ROOT]."/sigs/sigimage/Therfont.ttf";//The font I am using
$font_size = 8;// Font size
$y_start = 25;
$angle = 0;
$max_width = 450;// Maximum width for test

$sigs_array = file("sigs.txt");// Where my sigs are comming from
srand((double) microtime() * 10000000);
$sigs = array_rand($sigs_array);

$line_width = imagettfbbox($font_size, 0, $font_file, $sigs_array[$sigs]);

header("Content-type: image/png");
$im = imagecreatefrompng("blank.png");//What the sigs are being displayed on
$red = imagecolorallocate($im, 0, 0, 0);

imagettftext($im, $font_size, $angle, $x_start, $y_start, $red, $font_file, $sigs_array[$sigs]);

imagepng($im);
imagedestroy($im);
?>

 

I know that file( ) only pulls one line so is there something that allows me to put multiple lines or wrap the text?

Posted

Since you're turning the text into an image on the fly... I'm not so sure.

 

But what should work is putting either a carriage return or <br> in the string where you want the line break.

Posted

I've seen lots of classes devoted to image manipulation and creation. Are you hard coding this script into the TCH forums? I'd imagine there'd be an add on for invision board.

 

Sorry I can't be more help.

Posted

Rob, file() reads the file you specify and returns an array from which each element corresponds to a line in the file, with the newline still attached.

Posted (edited)

Oh! Sorry, I was very sleepy when I red this the first time and I didn't fully understand what you wanted to do.

 

OK, in that case, you're probably interested in fgets(). It reads bytes from a file. It ends reading when the specified number of bytes as been read or when a newline is found.

 

Just call it two times and you'll have two lines from your sigs.txt file :)

(I'm in a bit of a hurry, now but I think you can manage with this. If you still need help let me know. I'll drop by again in a couple of hours.)

Edited by TCH-Raul

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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