Hi all,
Due to work related boredom, I have decided to reach into the back of my dusty head and pull out the ol' PHP skills for a re-buff. I thought, hey, why not some kind of random sig image thing that I can include on messageboards? Sound. I hopped to it.
My implementation basically just pulled a random quote off of quotes.txt (In the same folder) and rendered it to a PNG file. I named the PHP file as a PNG file, and made a nifty .htaccess file that told apache that everything in that folder is PHP, so the png-but-not-really php file got actioned as PHP. Everything seems to work fine.
Thing is, the text is all blocky. If I include the image output on a html page with a black background, I get this: http://www.bs3.co.uk/jimssig/ Which is clearly ugly... Any ideas how I can tidy up the text some? Here's the code:
<?php
//defines
define("SIGLENGTH", 60);
define("IMAGEWIDTH", 400);
define("ROWHEIGHT", 20);
//Tell PHP that it is outputting a png
header("Content-type: image/png");
//What's the quotes file?
$sTextfile = "quotes.txt"; //quotes file
//get random quote
if ($aQuotes = @file($sTextfile)) //don't display errors on file open
{
//Wordwrap a random line out of the array
$sigtext = wordwrap( $aQuotes[array_rand($aQuotes)],SIGLENGTH, "<br>\n", 0);
}
else
{
//OR make the sig an error message
$sigtext = "Jim is broken";
}
//Count how many rows...
$numrows = substr_count($sigtext, '<br>');
//How tall does the image need to be because of this?
$imageheight = ($numrows + 1) * ROWHEIGHT;
//Create the image
$image = imagecreate(IMAGEWIDTH, $imageheight);
//Make up some colours
$background = imagecolorallocate($image, 255, 255, 255);
$textcolour = imagecolorallocate($image, 204, 204, 204);
//Make background transparent
imagecolortransparent($image, $background);
//Strip out any html
$sigtext = strip_tags($sigtext);
//make background colour
//imagefilledrectangle($image, 0, 0, $IMAGEWIDTH, $height, $background);
//Slap in text
imagettftext($image, 10, 0, 10, 10, $textcolour, "Dustismo.ttf", $sigtext);
//Push the completed image out.
imagepng($image);
//Finally, free up the memory allocated for the image.
imagedestroy($image);
//Shazam!
?>