Jump to content

Some GD questions.


foreverhex

Recommended Posts

Ok so I have a form that takes text and make an image out of it. I was wanting to know, is there a way to make the text wrap around in the inside of the image, instead of just disapearing off the image? Also is there a function to count how many lines the text would have? So that the hieght of the image could be ajusted accordingly? Like:
I am an apple
I like oranges
Third line yeah = 3 lines * 14px = 42
Link to comment
Share on other sites

You'll probably want to use wordwarp to addin a new line character every 20 characters. The use count and explode to get number of lines like so:
[code]<?php

$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br />\n");

echo $newtext . '<br /><br />';

echo 'There are ' . count(explode("\n", $newtext)) . ' lines';

?>[/code]
Link to comment
Share on other sites

ok when I try to do that I get
Warning: imagegif(): Unable to open 'filegif' for writing in /home/syblin83/public_html/testy.php on line 13
Maybe I have something wrong with my code. Here
[code]
<?php
$text = $_POST['poem'];

if(isset($text)) {
$newtext = wordwrap($text, 60, "\n", 1);
$im = imagecreate (525, 400);
$bgcolor = imagecolorallocate($im, 17, 0, 0);
$fontcolor = ImageColorAllocate ($im, 255, 255, 255);
imagecolortransparent($im, $bgcolor);
ImageTTFText ($im, 11, 0, 1, 20, $fontcolor, "arial.ttf",
"$newtext");
imagegif($im, file.gif);
imagedestroy($im);

} else {

$page_name = ' :: Poetry';
include 'top.php';

echo '<table class=body align=left valign=top>
<tr valign=top>
<td align=left>';

echo '<form action="testy.php" method="POST">
Insert text here:
<b>Discription:</b></td><td align=left><TEXTAREA Name=poem ROWS=8 COLS=40 style="color: #ffffff; background-color: #000000; border: solid #990000 1px; font-size: 12px;"></TEXTAREA>
<INPUT TYPE=Submit Value=" Upload Art " style="color: #00ff00; background-color: #000000; border: solid #990000 1px; font-size: 12px; width: 60px; height: 18px;">
</form>
</td></tr>
</table>';
} ?>
[/code]
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.