Ik heb "babelfish.ttf" en "avantgarde.ttf" in dezelfde map gezet.
hierbij is ip,host en date niet echt nodig, dat was voor het invullen (zoals bij jjapie)
Code: Select all
// eerst mysql database connecten
$link = mysql_connect("localhost", "naam", "ww");
mysql_select_db("db", $link);
//settings
$colors[0] = "#EE9999";
$colors[1] = "#99EE99";
$colors[2] = "#9999EE";
$colors[3] = "#EEEE99";
$colors[4] = "#99EEEE";
$colors[5] = "#EE99EE";
$fonts[0] = array("babelfish",18);
$fonts[4] = array("avantgarde",12);
$start_colour = "#EEEEEE";
$end_colour = "#CCCCCC";
$width = 350;
$height = 30;
//random font en grootte
srand ((float) microtime() * 10000000);
$fontNr = array_rand($fonts);
$fontFile = "./".$fonts[$fontNr][0].".ttf";
$fontSize = $fonts[$fontNr][1];
function parseColor($hex) {
$r = substr($hex,1,2);
$g = substr($hex,3,2);
$b = substr($hex,5,2);
return array(hexdec($r),hexdec($g),hexdec($b));
}
function getRandomColor() {
global $colors, $im;
srand ((float) microtime() * 10000000);
$rand_keys = array_rand($colors);
$color = $colors[$rand_keys];
list($r,$g ,$b) = parseColor($color);
return imagecolorallocate($im, $r, $g, $b);
}
// get signatures
$sql = "SELECT sig FROM forum_sig ORDER BY date DESC"; //LIMIT 10 OFFSET 0
$result = mysql_query($sql) or die ("Mysql error: ".mysql_error());
if(mysql_num_rows($result) > 0) {
while($data = mysql_fetch_array($result)) {
$sig[] = $data;
}
}
// get random out of latest ten //
srand ((float) microtime() * 10000000);
$rand_key = array_rand($sig);
$sigText = $sig[$rand_key]['sig'];
// build image //
$im = imagecreate($width, $height);
$bgc = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, $width, $height, $bgc);
// create fade
list($start_r,$start_g,$start_b) = parseColor($start_colour);
list($end_r,$end_g,$end_b) = parseColor($end_colour);
//LOOP THROUGH ALL THE PIXELS
for($y=0; $y < $height; $y++) {
//CALCULATE THIS ROWS RGB COLOURS
$new_r = $start_r - intval((($start_r - $end_r)/$height)*$y);
$new_g = $start_g - intval((($start_g - $end_g)/$height)*$y);
$new_b = $start_b - intval((($start_b - $end_b)/$height)*$y);
//ALLOCATE THE COLOR
$row_color = imagecolorresolve($im, $new_r, $new_g, $new_b);
for($x=0; $x < $width; $x++) {
//CREATE ROW OF THIS COLOR
imagesetpixel($im, $x, $y, $row_color);
}
}
// write text //
//imagestring($im, 5, 0, 0, $sigText, $color1);
list($r,$g,$b) = parseColor("#222222");
$color1 = imagecolorallocate($im,$r,$g,$b); //getRandomColor();
list($r,$g,$b) = parseColor("#BBBBBB");
$color3 = imagecolorallocate($im,$r,$g,$b);
$color2 = getRandomColor();
imagettftext($im, $fontSize, 0, 11, 26, $color3, $fontFile, $sigText);
imagettftext($im, $fontSize, 0, 6, 23, $color1, $fontFile, $sigText);
imagettftext($im, $fontSize, 0, 6, 21, $color1, $fontFile, $sigText);
imagettftext($im, $fontSize, 0, 4, 21, $color1, $fontFile, $sigText);
imagettftext($im, $fontSize, 0, 4, 23, $color1, $fontFile, $sigText);
imagettftext($im, $fontSize, 0, 5, 22, $color2, $fontFile, $sigText);
imagejpeg($im,"",98);
imagedestroy($im);
flush();