Jump to content

imagepng() and wordwrap()


jackpf

Recommended Posts

Good...morning  all.

 

So yeah, I'm making a random quotes thing, probably like so many of you have done so yourselves.

 

Anyway, I'm using wordwrap(), to wordwrap the quotes (suprisingly). But instead of inserting a new line, it inserts some weird symbol. I couldn't find anyting on google. Just wondering how you guys managed it.

 

Yeah, this is basically my code thus far:

$sql = mysql_query("SELECT * FROM `$tb_Quote` WHERE `Status`='1' ORDER BY RAND();") or trigger_error(mysql_error(), E_USER_ERROR);
$fetch = mysql_fetch_array($sql);
$author = $fetch['Author'];
$quote = wordwrap($fetch['Quote'], 50);

$img = imagecreate(450, 75);

imagecolorallocate($img, 0, 0, 0);
$text_colour = imagecolorallocate($img, 255, 255, 255);
$line_colour = imagecolorallocate($img, 128, 255, 0);

imagestring($img, 2, 2, 5, 'Quote from '.$author, $text_colour);
imageline($img, 0, 20, imageSx($img), 20, $line_colour);
imagestring($img, 2, 2, 30, $quote, $text_colour);

header('Content-type: image/png');
imagepng($img);
imagedestroy($img);

 

Cheers,

Jack.

 

Oh, here's an example btw. Just refresh the page a couple of times to get a long quote, and you'll see what I mean - http://jackpf.000space.com/quote.php

Link to comment
https://forums.phpfreaks.com/topic/159007-imagepng-and-wordwrap/
Share on other sites

I'm not seeing any weird character.

 

I did something like this once. I measured to the last space before the length limit and broke the lines into an array. Then cycled through the array, "printing" one line at a time. Unfortunately, I think the actual code is on a backup DVD someplace, and not close at hand.

Archived

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

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