Once I figure out how to wrap the stuff better (It works on my local server, not on my test server)
Here's the code though
<?php
//Released under GPL
//Copyright (C) 2004 devicenull (darkmage at snet dot net)
header("Content-type: image/png");
$sql_host = "127.0.0.1";
$sql_user = "";
$sql_pass = "";
$sql_db = "";
$sql_user = "root";
$sql_pass = "starfox";
$sql_db = "site";
$font = "./verdana.ttf";
$y_start = 0;
$fsize = 8;
$max_width = 400;
//Open connection for post count
$link = mysql_connect($sql_host, $sql_user, $sql_pass)
or die("Could not connect : " . mysql_error());
mysql_select_db($sql_db,$link)
or die("Could not select database");
//If the table doesnt exist, create it
$query = "CREATE TABLE IF NOT EXISTS `ip_log` (`id` INT(11) NOT NULL auto_increment, `ipaddress` VARCHAR(64) NOT NULL, `count` INT(11) NOT NULL, PRIMARY KEY (`id`)) TYPE=MyISAM;";
mysql_query($query,$link);
$ip = $_SERVER['REMOTE_ADDR'];
//Get random quote
$quotes_array = file("./quotes.txt");
$quote = array_rand($quotes_array);
if ($quotes_array[$quote] == "IP_ADDR") {
$quotes_array[$quote] = "Hi ".$ip;
}
//Get IP count
$res = mysql_query("SELECT * FROM `ip_log` WHERE ipaddress='".$ip."'",$link);
if (mysql_num_rows($res) == 0) {
mysql_query("INSERT INTO `ip_log` VALUES ('','".$ip."',1)",$link);
$count = 1;
} else {
$row = mysql_fetch_row($res);
$count = (int)$row[2];
$count++;
$id = $row[0];
$query = "UPDATE `ip_log` SET count='".$count."' WHERE id='".$id."'";
mysql_query($query,$link);
mysql_free_result($res);
}
$text = "You have read ".$count." of my posts";
//----------------------------------------------------------------------
// Image Generation
//----------------------------------------------------------------------
//imagettfbbox ( float size, float angle, string fontfile, string text)
// 6,7-----------------4,5
// | |
// 0,1-----------------2,3
//imagefilledrectangle (image, int x1, int y1, int x2, int y2, int color)
//imagettftext (image, float size, float angle, int x, int y, int color, string fontfile, string text)
//$im = imagecreate($width, $height);
$quotes_array[$quote] = wordwrap($quotes_array[$quote],65,"\n");
$im = imagecreatefrompng("sig_img.png");
//$bg = imagecolorallocatealpha($im, 255, 255, 255, 127);
$fg = imagecolorresolve($im, 0, 0, 0);
imagettftext($im, $fsize, 0.0, 33, 15, $fg, $font, $quotes_array[$quote]);
imagettftext($im, $fsize, 0.0, 200, 48, $fg, $font, $text);
imagepng($im);
imagedestroy($im);
?>