MyBB forum stats PHP image

Reputation
0
I made a php image that shows MyBB forum stats for eXore.
His host didn't support imagettftext() for some reason, but anyway, you can check it out here (Scroll down to the bottom of the OP).

If you want to use this yourself the source is here.

PHP:
<?php
	header("Content-type: image/png");

	// ----------------------------

	$mysql_host  = "localhost";
	$mysql_user  = "root";
	$mysql_pass  = "";
	$mysql_db    = "forum";
	$mysql_table = "mybb_stats";

	// ----------------------------

	$con = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
	mysql_select_db($mysql_db);

	$q = mysql_query("SELECT * FROM mybb_stats ORDER BY dateline DESC LIMIT 1");
	$row = mysql_fetch_array($q);
	$stats['posts'] = $row['numposts'];
	$stats['threads'] = $row['numthreads'];
	$stats['users'] = $row['numusers'];

	$img = imagecreatetruecolor(150, 52);

	$color['gray'] = imagecolorallocate($img, 51, 51, 51);
	$color['white'] = imagecolorallocate($img, 255, 255, 255);

	imagefill($img, 0, 0, $color['gray']);

	imagettftext($img, 11, 0, 5, 15, $color['white'], "font.ttf", "Members: ".$stats['users']);
	imagettftext($img, 11, 0, 5, 30, $color['white'], "font.ttf", "Threads: ".$stats['threads']);
	imagettftext($img, 11, 0, 5, 45, $color['white'], "font.ttf", "Posts: ".$stats['posts']);

	imagepng($img);
	imagedestroy($img);

	mysql_close($con);
?>

You can download the font I use here.

Enjoy :)
 
Back
Top