Code:
<?php
/* Ramie A.K.A SomeBrownKid ([email protected])
* THIS IS NOT 100% MINE, Allen helped me with the image functions.
* ICS3U1 - 02 (Richmond Green Secondary School)
* November 30th 2010
*/
// Set the content-type
header('Content-type: image/png');
//**************IMAGE VARIABLE CHANGE*********************/
//setImages
$online_img = (isset($_GET['onimg'])) ? $_GET['onimg'] : 'OnlineImageName'; //Online Image Name (Make sure its in same directory)
$online = ping($ghost, $gport);
/////////////////////////ALLEN'S WORK!////////////////////////////////////////////
// Get variables
$text = (isset($_GET['text'])) ? $_GET['text'] : '32';
$boxText = "T"; //use a sample size to calculate the base height and width of this imagetext
$angle = (isset($_GET['angle'])) ? $_GET['angle'] : 0;
$align = (isset($_GET['align'])) ? $_GET['align'] : 'center';
$font_size = (isset($_GET['font_size'])) ? $_GET['font_size'] : 24;
$font = (isset($_GET['font'])) ? "./".$_GET['font'] : './arial.ttf';
$r = (isset($_GET['r'])) ? $_GET['r'] : 255;
$g = (isset($_GET['g'])) ? $_GET['g'] : 255;
$b = (isset($_GET['b'])) ? $_GET['b'] : 255;
$rs = (isset($_GET['rs'])) ? $_GET['rs'] : 0;
$gs = (isset($_GET['gs'])) ? $_GET['gs'] : 0;
$bs = (isset($_GET['bs'])) ? $_GET['bs'] : 0;
$shadow = (isset($_GET['shadow'])) ? $_GET['shadow'] : 0;
$shadow_dist = (isset($_GET['shadow_dist'])) ? $_GET['shadow_dist'] : 1;
$shadow_size = (isset($_GET['shadow_size'])) ? $_GET['shadow_size'] : $font_size;
$x = (isset($_GET['x'])) ? $_GET['x'] : 0;
$y = (isset($_GET['y'])) ? $_GET['y'] : 0;
$border = (isset($_GET['border'])) ? $_GET['border'] : 0;
/////////////////////////ALLEN'S WORK!////////////////////////////////////////////
//create image file, with provided path
$im = @imagecreatefrompng($online_img);
$text_colour = imagecolorallocate($im, $r, $g, $b);
//find out the bounding box of the text (lowerLeft, lowerRight, upperRight, upperLeft
$bbox = imagettfbbox($font_size, $angle, $font, $text);
$width = abs($bbox[2] - $bbox[0]);
$bbox = imagettfbbox($font_size, $angle, $font, $boxText);
$height = abs($bbox[7] - $bbox[1]);
// This is our cordinates for X and Y
if ($align == "left") {
$x += 0;
$y += height;
} else if ($align == "right") {
$x += imagesx($im) - $width;
$y += $height;
} else if ($align == "center") {
$x += round((imagesx($im) - $width)/2);
$y += round((imagesy($im) + $height)/2);
}
// Add some shadow to the text
if ($shadow) {
imagettftext($im, $font_size, $angle, $x+$shadow_dist, $y+$shadow_dist, $shadow_colour, $font, $text);
}
if ($border) {
imagettfborder($im, $font_size, $angle, $x, $y, $text_colour, $font, $text, $border);
}
// Add the text
imagettftext($im, $font_size, $angle, $x, $y, $text_colour, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
//function for server status
function ping($host, $port){
$s = @fsockopen($host, $port, $ERROR_NO, $ERROR_STR,(float)0.5);
if($s) {
@fclose($s);
return true;
} else {
return false;
}
}
function imagettfborder($im, $size, $angle, $x, $y, $color, $font, $text, $width) {
// top
imagettftext($im, $size, $angle, $x-$width, $y-$width, $color, $font, $text);
imagettftext($im, $size, $angle, $x, $y-$width, $color, $font, $text);
imagettftext($im, $size, $angle, $x+$width, $y-$width, $color, $font, $text);
// bottom
imagettftext($im, $size, $angle, $x-$width, $y+$width, $color, $font, $text);
imagettftext($im, $size, $angle, $x, $y+$width, $color, $font, $text);
imagettftext($im, $size, $angle, $x-$width, $y+$width, $color, $font, $text);
// left
imagettftext($im, $size, $angle, $x-$width, $y, $color, $font, $text);
// right
imagettftext($im, $size, $angle, $x+$width, $y, $color, $font, $text);
for ($i = 1; $i < $width; $i++) {
// top line
imagettftext($im, $size, $angle, $x-$i, $y-$width, $color, $font, $text);
imagettftext($im, $size, $angle, $x+$i, $y-$width, $color, $font, $text);
// bottom line
imagettftext($im, $size, $angle, $x-$i, $y+$width, $color, $font, $text);
imagettftext($im, $size, $angle, $x+$i, $y+$width, $color, $font, $text);
// left line
imagettftext($im, $size, $angle, $x-$width, $y-$i, $color, $font, $text);
imagettftext($im, $size, $angle, $x-$width, $y+$i, $color, $font, $text);
// right line
imagettftext($im, $size, $angle, $x+$width, $y-$i, $color, $font, $text);
imagettftext($im, $size, $angle, $x+$width, $y+$i, $color, $font, $text);
}
}
?>
Make sure you replace this code with
Code:
<?
/* Ramie A.K.A SomeBrownKid ([email protected])
* This is a php script designed to display the amount of players online in an image.
* ICS3U1 - 02 (Richmond Green Secondary School)
* November 30th 2010
*/
// Set the content-type
header('Content-type: image/png');
#Game Server
$ghost = " "; // Server IP / Host name
#Game Port
$gport = " "; //Server Port
// Make a MySQL Connection
mysql_connect("--", "--", "--") or die(mysql_error()); //Add your own information here HOST/User/Password
mysql_select_db("--") or die(mysql_error()); //Database Name
//Query
$online = mysql_query("SELECT * FROM online WHERE id = 1");
//put the query result into a var
$totalonline = mysql_fetch_array($online);
//set up img sources
$online_img = 'OnlineImageName.png'; //Replace with your own
$offline_img = 'OfflineImageName.png';
function ping($host, $port){ //We are sending packets to the designated computer to see if there is a response
$s = @fsockopen($host, $port, $ERROR_NO, $ERROR_STR,(float)0.5);
if($s) {
@fclose($s);
return true;
} else {
return false;
}
}
if (ping($ghost, $gport)) { //Pinging function takes place
$online = $totalonline['currentlyonline'];
// Get variables
$text = $online;
$boxText = "T"; //use a sample size to calculate the base height and width of this imagetext
$angle = (isset($_GET['angle'])) ? $_GET['angle'] : 0;
$align = (isset($_GET['align'])) ? $_GET['align'] : 'center';
$font_size = (isset($_GET['font_size'])) ? $_GET['font_size'] : 24;
$font = "./neuropol.ttf";
$r = (isset($_GET['r'])) ? $_GET['r'] : 255;
$g = (isset($_GET['g'])) ? $_GET['g'] : 255;
$b = (isset($_GET['b'])) ? $_GET['b'] : 255;
$rs = (isset($_GET['rs'])) ? $_GET['rs'] : 0;
$gs = (isset($_GET['gs'])) ? $_GET['gs'] : 0;
$bs = (isset($_GET['bs'])) ? $_GET['bs'] : 0;
$shadow = (isset($_GET['shadow'])) ? $_GET['shadow'] : 0;
$shadow_dist = (isset($_GET['shadow_dist'])) ? $_GET['shadow_dist'] : 1;
$shadow_size = (isset($_GET['shadow_size'])) ? $_GET['shadow_size'] : $font_size;
$x = 40;
$y = 28;
$border = (isset($_GET['border'])) ? $_GET['border'] : 0;
//create image file, with provided path
$im = @imagecreatefrompng($online_img);
$text_colour = imagecolorallocate($im, $r, $g, $b);
//find out the bounding box of the text (lowerLeft, lowerRight, upperRight, upperLeft
$bbox = imagettfbbox($font_size, $angle, $font, $text);
$width = abs($bbox[2] - $bbox[0]);
$bbox = imagettfbbox($font_size, $angle, $font, $boxText);
$height = abs($bbox[7] - $bbox[1]);
// This is our cordinates for X and Y
if ($align == "left") {
$x += 0;
$y += height;
} else if ($align == "right") {
$x += imagesx($im) - $width;
$y += $height;
} else if ($align == "center") {
$x += round((imagesx($im) - $width)/2);
$y += round((imagesy($im) + $height)/2);
}
// Add some shadow to the text
if ($shadow) {
imagettftext($im, $font_size, $angle, $x+$shadow_dist, $y+$shadow_dist, $shadow_colour, $font, $text);
}
if ($border) {
imagettfborder($im, $font_size, $angle, $x, $y, $text_colour, $font, $text, $border);
}
// Add the text
imagettftext($im, $font_size, $angle, $x, $y, $text_colour, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
}else{
$im = @imagecreatefrompng($offline_img); //Create the image
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
}
if(isset($conn)){
mysql_close($conn); //Close the connection Thank you whoever pointed it out in my last tutorial ;)
}
?>
Finished the PHP Scripts!