[php] Status & user count image generator

Development of graphics and web assets.

[php] Status & user count image generator

Postby Ramy » Sun Mar 18, 2012 11:26 am

This is done with GD and php, What it does is generate an image for each request (with [img] tags or anywhere you like to place it) with the current status of your server.

Example:
Image

Code: Select all

<?php

include 'header.php'; // include your db/query class here

// get users online
$query_getusercount = new query($SQL, "SELECT count(*) as icount  FROM CURRENTUSER");
$query_getusercount->fetch() ;
$intuser = $query_getusercount->field('icount');



$imgp = "./img/img.PNG";  // your background image
$im = imagecreatefrompng($imgp);
$stamp = imagecreatetruecolor(140, 70); //size of your infobox
$im = imagecreatefrompng($imgp);

error_reporting(0);
$icount = 0;
// change the array to your hostname:port
$IP = array(
"Login Server" => "soma.shinra-co.net:1111",
"Session Server" => "soma.shinra-co.net:1110",
"1p1 Server" => "soma.shinra-co.net:12000",
"Game Server" => "soma.shinra-co.net:1120");

while(list($ServerName,$Host)=each($IP)) {
list($IPAddress,$Port)=explode(":",$Host);
 imagestring($stamp, 2, 1, $icount , $ServerName.": ", 0xFFFFFF);
if($fp=fsockopen($IPAddress,$Port,$ERROR_NO, $ERROR_STR ,(float)1.5)) {
imagestring($stamp, 2 , 100,  $icount, "Online", 0x008000);
fclose($fp);
}
else {
imagestring($stamp, 2, 100, $icount, "Maintainance", 0xBF0000 );

$icount+=13;
}
imagestring($stamp, 2, 1, $icount , "Users online: ".$intuser, 0xFFFFFF);
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp),

imagesy($stamp), 50);
header('Content-Type: image/png');
imagesavealpha( $im, true );

imagepng($im);
imagedestroy($im);


?>


This should be useful for server advertisement threads. (db and query class not included)
User avatar
Ramy
SD Four Star
SD Four Star
 
Posts: 213
Joined: Fri Feb 29, 2008 1:20 pm

Re: [php] Status & user count image generator

Postby phoenixgolden » Sun Mar 18, 2012 1:00 pm

okay ill realiy like this thanks ramy :) good job xD

Image
Phoenix.

Image

Human @Inca SomaDev (retired)
phoenixgolden
SD Pro 5 Star
SD Pro 5 Star
 
Posts: 1170
Joined: Sat Oct 08, 2011 9:24 pm


Return to Graphics and Website development

Who is online

Users browsing this forum: No registered users and 3 guests

cron