Jump to content

Archived

This topic is now archived and is closed to further replies.

foreverhex

Some GD questions.

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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
Ok I tweaked what you gave me a bit and its all looking well thx. But, how do you save the file? I never really could understand the uploading scripts so Im not sure how you do this.

Share this post


Link to post
Share on other sites
if you want to save a jpeg, put the path into the second argument of imagejpeg()

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
[code]<?php
imagegif($im, "file.gif");
?>[/code]

Also make sure that the folder is writeable.

Share this post


Link to post
Share on other sites

×

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.