<?php
//Tell the browser its a jpeg
header('Content-type: image/jpeg');
//Get server ip/port
$ipp = $_GET['ipp'];
$stripp = $_GET['stripp'];
$usercolor = $_GET['usercolor'];
$addy_s = split(":", $ipp);
$s_addy = $addy_s[0];
$s_port = $addy_s[1];
require_once("db.php");
require_once("load_servers.php");
$server_array = array();
$ServerClass = new ServerClass();
$ServerClass->load_server_db($db);
$server_a = $ServerClass->load_banner_server($s_addy, $s_port);
//$callname = 'http://www.guiddb.com/api/get_server_info.php?server=' . $ipp;
//$result = file($callname);
//$results = unserialize($result[0]);
$results['mapname'] = $server_a['map'];
$results['hostname_c'] = $server_a['name'];
$results['aliases'] = $server_a['num_a'];
$results['nowplaying'] = $server_a['players'];
$results['maxclients'] = $server_a['slots'];
//Include tga file handler
//include 'tgafilehandler.php';
//Set mapname for banner
$mapname = $results['mapname'];
//Set banner file to start with
$bannerfile = 'images/' . $mapname . '.jpg';
//Check for banner, if non exist try to create
if (!file_exists($bannerfile)) {
//Set all the vars needed for generated the banner
$pk3file = 'q3ut4/' . $mapname . '.pk3';
$lvlshot = 'levelshots/' . $mapname . '.jpg';
$baseimagename = 'images/levelshots/' . $mapname;
$tgafile = 'images/levelshots/' . $mapname . '.tga';
$outjpeg = 'images/levelshots/' . $mapname . '.jpg';
//Open the pk3 and get the levelshot
$zip = new ZipArchive;
$res = $zip->open($pk3file);
if ($res === TRUE) {
if (!$zip->extractTo('images/', $lvlshot) === TRUE) {
$lvlshot = 'levelshots/' . $mapname . '.tga';
$zip->extractTo('images/', $lvlshot);
}
$zip->close();
}
//If there is no jpg but a tga, *try* and convert it, doesnt work very well.
//if (!file_exists($outjpeg) && file_exists($tgafile)) {
// tga2jpg ("$baseimagename" );
// Return the resource image alone
//$resource_image = imagecreatefromtga ( "$tgafile" );
// Declare the content-type as a JPEG image.
//header ( 'Content-type: image/jpeg' );
// Convert the image to JPEG for smaller file size and compatability
//imagejpeg ( $resource_image, $outjpeg, 100 );
//Close image
//imagedestroy ( $resource_image );
//}
//If no jpeg exists as of now set the banner to default, else make banner from levelshot
if (!file_exists($outjpeg)) {
$bannerfile = 'images/banner-blank.jpg';
}
else {
//Load levelshot jpeg
$lvlshotimage = imageCreateFromJPEG($outjpeg);
//Get x for levelshot
$lvlshottx = imagesx($lvlshotimage);
//Get y for levelshot
$lvlshotty = imagesy($lvlshotimage);
//Set y offset for crop
$lvlshotsy = $lvlshotty * .352;
//Set size of y crop
$lvlshotly = $lvlshotty * .229;
//Create new image for the map banner
$bannerout = imagecreatetruecolor( 468, 80 );
//Turn on AA for images
//imageantialias($lvlshotimage, true);
//imageantialias($bannerout, true);
//Set jpeg header info
header ( 'Content-type: image/jpeg' );
//Copy and resize from levelshot to new banner
imagecopyresized($bannerout, $lvlshotimage, 0, 0, 0, $lvlshotsy, 468, 80, $lvlshottx, $lvlshotly);
//Output jpeg to bannerfile for map
imagejpeg($bannerout, $bannerfile, 100);
//Close both images
imagedestroy ($bannerout);
imagedestroy ($lvlshotimage);
}
}
//Create the base image from the default banner
$preimage = imageCreateFromJPEG($bannerfile);
$superimp = imagecreatetruecolor( 468, 80 );
$precolors = array(
'black' => imagecolorallocate($superimp, 0, 0, 0),
'white' => imageColorAllocate($superimp, 255, 255, 255),
'grey' => imageColorAllocate($superimp, 128, 128, 128),
);
//Turn on anti-aliasing functions for the image
//imageantialias($preimage, true);
//imageantialias($superimp, true);
imagefill($superimp, 0, 0, $precolors['grey']);
imagefilledrectangle($superimp, 5, 5, 25, 75, $precolors['black']);
imagefilledrectangle($superimp, 30, 3, 463, 27, $precolors['white']);
imagefilledrectangle($superimp, 30, 30, 285, 53, $precolors['white']);
imagefilledrectangle($superimp, 290, 30, 463, 53, $precolors['white']);
imagecopymerge($preimage, $superimp, 0, 0, 0, 0, 468, 80, 33);
imageJPEG($preimage, 'images/current-render.jpg', 100);
imageDestroy($preimage);
imageDestroy($superimp);
$image = imageCreateFromJPEG('images/current-render.jpg');
//imageantialias($image, true);
$hexcolors = array(
'aliceblue'=>'F0F8FF',
'antiquewhite'=>'FAEBD7',
'aqua'=>'00FFFF',
'aquamarine'=>'7FFFD4',
'azure'=>'F0FFFF',
'beige'=>'F5F5DC',
'bisque'=>'FFE4C4',
'black'=>'000000',
'blanchedalmond '=>'FFEBCD',
'blue'=>'0000FF',
'blueviolet'=>'8A2BE2',
'brown'=>'A52A2A',
'burlywood'=>'DEB887',
'cadetblue'=>'5F9EA0',
'chartreuse'=>'7FFF00',
'chocolate'=>'D2691E',
'coral'=>'FF7F50',
'cornflowerblue'=>'6495ED',
'cornsilk'=>'FFF8DC',
'crimson'=>'DC143C',
'cyan'=>'00FFFF',
'darkblue'=>'00008B',
'darkcyan'=>'008B8B',
'darkgoldenrod'=>'B8860B',
'darkgray'=>'A9A9A9',
'darkgreen'=>'006400',
'darkgrey'=>'A9A9A9',
'darkkhaki'=>'BDB76B',
'darkmagenta'=>'8B008B',
'darkolivegreen'=>'556B2F',
'darkorange'=>'FF8C00',
'darkorchid'=>'9932CC',
'darkred'=>'8B0000',
'darksalmon'=>'E9967A',
'darkseagreen'=>'8FBC8F',
'darkslateblue'=>'483D8B',
'darkslategray'=>'2F4F4F',
'darkslategrey'=>'2F4F4F',
'darkturquoise'=>'00CED1',
'darkviolet'=>'9400D3',
'deeppink'=>'FF1493',
'deepskyblue'=>'00BFFF',
'dimgray'=>'696969',
'dimgrey'=>'696969',
'dodgerblue'=>'1E90FF',
'firebrick'=>'B22222',
'floralwhite'=>'FFFAF0',
'forestgreen'=>'228B22',
'fuchsia'=>'FF00FF',
'gainsboro'=>'DCDCDC',
'ghostwhite'=>'F8F8FF',
'gold'=>'FFD700',
'goldenrod'=>'DAA520',
'gray'=>'808080',
'green'=>'008000',
'greenyellow'=>'ADFF2F',
'grey'=>'808080',
'honeydew'=>'F0FFF0',
'hotpink'=>'FF69B4',
'indianred'=>'CD5C5C',
'indigo'=>'4B0082',
'ivory'=>'FFFFF0',
'khaki'=>'F0E68C',
'lavender'=>'E6E6FA',
'lavenderblush'=>'FFF0F5',
'lawngreen'=>'7CFC00',
'lemonchiffon'=>'FFFACD',
'lightblue'=>'ADD8E6',
'lightcoral'=>'F08080',
'lightcyan'=>'E0FFFF',
'lightgoldenrodyellow'=>'FAFAD2',
'lightgray'=>'D3D3D3',
'lightgreen'=>'90EE90',
'lightgrey'=>'D3D3D3',
'lightpink'=>'FFB6C1',
'lightsalmon'=>'FFA07A',
'lightseagreen'=>'20B2AA',
'lightskyblue'=>'87CEFA',
'lightslategray'=>'778899',
'lightslategrey'=>'778899',
'lightsteelblue'=>'B0C4DE',
'lightyellow'=>'FFFFE0',
'lime'=>'00FF00',
'limegreen'=>'32CD32',
'linen'=>'FAF0E6',
'magenta'=>'FF00FF',
'maroon'=>'800000',
'mediumaquamarine'=>'66CDAA',
'mediumblue'=>'0000CD',
'mediumorchid'=>'BA55D3',
'mediumpurple'=>'9370D0',
'mediumseagreen'=>'3CB371',
'mediumslateblue'=>'7B68EE',
'mediumspringgreen'=>'00FA9A',
'mediumturquoise'=>'48D1CC',
'mediumvioletred'=>'C71585',
'midnightblue'=>'191970',
'mintcream'=>'F5FFFA',
'mistyrose'=>'FFE4E1',
'moccasin'=>'FFE4B5',
'navajowhite'=>'FFDEAD',
'navy'=>'000080',
'oldlace'=>'FDF5E6',
'olive'=>'808000',
'olivedrab'=>'6B8E23',
'orange'=>'FFA500',
'orangered'=>'FF4500',
'orchid'=>'DA70D6',
'palegoldenrod'=>'EEE8AA',
'palegreen'=>'98FB98',
'paleturquoise'=>'AFEEEE',
'palevioletred'=>'DB7093',
'papayawhip'=>'FFEFD5',
'peachpuff'=>'FFDAB9',
'peru'=>'CD853F',
'pink'=>'FFC0CB',
'plum'=>'DDA0DD',
'powderblue'=>'B0E0E6',
'purple'=>'800080',
'red'=>'FF0000',
'rosybrown'=>'BC8F8F',
'royalblue'=>'4169E1',
'saddlebrown'=>'8B4513',
'salmon'=>'FA8072',
'sandybrown'=>'F4A460',
'seagreen'=>'2E8B57',
'seashell'=>'FFF5EE',
'sienna'=>'A0522D',
'silver'=>'C0C0C0',
'skyblue'=>'87CEEB',
'slateblue'=>'6A5ACD',
'slategray'=>'708090',
'slategrey'=>'708090',
'snow'=>'FFFAFA',
'springgreen'=>'00FF7F',
'steelblue'=>'4682B4',
'tan'=>'D2B48C',
'teal'=>'008080',
'thistle'=>'D8BFD8',
'tomato'=>'FF6347',
'turquoise'=>'40E0D0',
'violet'=>'EE82EE',
'wheat'=>'F5DEB3',
'white'=>'FFFFFF',
'whitesmoke'=>'F5F5F5',
'yellow'=>'FFFF00',
'yellowgreen'=>'9ACD32');
$colors = array();
foreach ($hexcolors as $color => $hex) {
list($r, $g, $b) = sscanf($hexcolors[$color], "%02x%02x%02x");
$colors[$color] = imageColorAllocate($image, $r, $g, $b);
}
//Define colors to be used in image
/*
$colors = array(
'grey' => imagecolorallocate($image, 128, 128, 128),
'black' => imageColorAllocate($image, 0, 0, 0),
'darkred' => imageColorAllocate($image, 170, 0, 0),
'red' => imageColorAllocate($image, 255, 0, 0),
'green' => imageColorAllocate($image, 0, 255, 0),
'brightgreen' => imageColorAllocate($image, 50, 255, 43),
'darkgrey' => imageColorAllocate($image, 36, 36, 36),
'blue' => imageColorAllocate($image, 0, 0, 255),
'yellow' => imageColorAllocate($image, 255, 255, 0),
'brightblue' => imageColorAllocate($image, 0, 255, 255),
'purple' => imageColorAllocate($image, 255, 0, 255),
'white' => imageColorAllocate($image, 255, 255, 255),
);
*/
if (!$usercolor) {
$usercolor = 'brightgreen';
}
//Set font to be used for the static text
$font = './gothicb.ttf';
//Set static text vars
$maptext = 'Map :';
$nametext = 'Server name :';
$iptext = 'IP :';
$playertext = 'Players :';
$aliastext = "Collected Alias's :";
//Set all active text vars
$sv = $results['hostname_c'];
$servertext = $ipp;
$numalias = $results['aliases'];
$servername = substr($sv, 0, 35);
//Explode sv_hostname at any color codes
$servernamepieces = explode("^", $servername);
for($i = 0, $size = sizeof($servernamepieces); $i < $size; ++$i)
{
//Get color code
$colorcode = substr($servernamepieces[$i], 0, 1);
//Determine color
switch ($colorcode) {
case 0:
$servernamecolors[$i] = 'white';
break;
case 1:
$servernamecolors[$i] = 'red';
break;
case 2:
$servernamecolors[$i] = 'green';
break;
case 3:
$servernamecolors[$i] = 'yellow';
break;
case 4:
$servernamecolors[$i] = 'blue';
break;
case 5:
$servernamecolors[$i] = 'brightblue';
break;
case 6:
$servernamecolors[$i] = 'purple';
break;
case 7:
$servernamecolors[$i] = 'black';
break;
}
$strp = strpos($sv, '^');
//Strip color code from segment
if ($strp == false) {
$servernamepiece[$i] = substr($servernamepieces[$i], 0);
} else {
$servernamepiece[$i] = substr($servernamepieces[$i], 0);
}
}
//Math for the player meter
$totalplayers = $results['nowplaying'];
$totalslots = $results['maxclients'];
$percentplayers = ($totalplayers / $totalslots);
$totalgraph = (7 + ((1 - $percentplayers) * 66));
$numplayers = $totalplayers . ' / ' . $totalslots;
//gaussian blur matrix
$gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0));
//Background for player meter
//Output phase 1 of static text, white blurred background
imagettftext($image, 16, 0, 36, 22, $colors[$usercolor], $font, $nametext);
imagettftext($image, 16, 0, 35, 23, $colors[$usercolor], $font, $nametext);
imagettftext($image, 16, 0, 34, 22, $colors[$usercolor], $font, $nametext);
imagettftext($image, 16, 0, 35, 21, $colors[$usercolor], $font, $nametext);
imagettftext($image, 16, 0, 35, 50, $colors[$usercolor], $font, $iptext);
imagettftext($image, 16, 0, 36, 49, $colors[$usercolor], $font, $iptext);
imagettftext($image, 16, 0, 34, 49, $colors[$usercolor], $font, $iptext);
imagettftext($image, 16, 0, 35, 48, $colors[$usercolor], $font, $iptext);
imagettftext($image, 16, 0, 296, 49, $colors[$usercolor], $font, $playertext);
imagettftext($image, 16, 0, 295, 50, $colors[$usercolor], $font, $playertext);
imagettftext($image, 16, 0, 295, 48, $colors[$usercolor], $font, $playertext);
imagettftext($image, 16, 0, 294, 49, $colors[$usercolor], $font, $playertext);
imagettftext($image, 12, 0, 35, 73, $colors[$usercolor], $font, $aliastext);
imagettftext($image, 12, 0, 36, 72, $colors[$usercolor], $font, $aliastext);
imagettftext($image, 12, 0, 34, 72, $colors[$usercolor], $font, $aliastext);
imagettftext($image, 12, 0, 35, 71, $colors[$usercolor], $font, $aliastext);
imagettftext($image, 12, 0, 266, 72, $colors[$usercolor], $font, $maptext);
imagettftext($image, 12, 0, 265, 73, $colors[$usercolor], $font, $maptext);
imagettftext($image, 12, 0, 265, 71, $colors[$usercolor], $font, $maptext);
imagettftext($image, 12, 0, 264, 72, $colors[$usercolor], $font, $maptext);
//Output the backdrop of the server name in white
$sx = 180;
for($i = 0, $size = sizeof($servernamepiece); $i < $size; ++$i)
{
//Set color for segment
if ($stripp == true) {
$color = 'black';
} else {
$color = $servernamecolors[$i];
}
//Get font bounding box info
$bbox = imagettfbbox(13, 0, $font, $servernamepiece[$i]);
//Set the lower left x cordinate with starting offset
$x = $bbox[0] + $sx;
//Draw this piece of sv_hostname backdrop with color
imagettftext($image, 13, 0, $x, 23, $colors[$color], $font, $servernamepiece[$i]);
imagettftext($image, 13, 0, ($x - 1), 22, $colors[$color], $font, $servernamepiece[$i]);
imagettftext($image, 13, 0, ($x + 1), 22, $colors[$color], $font, $servernamepiece[$i]);
imagettftext($image, 13, 0, $x, 21, $colors[$color], $font, $servernamepiece[$i]);
//Set the new starting offset for next piece of sv_hostname by
//adding the lower right x cordinate to current offset
$sx = $sx + $bbox[2] + 2;
}
//Server ip/port all black
imagettftext($image, 12, 0, 72, 50, $colors['black'], $font, $servertext);
imagettftext($image, 12, 0, 73, 49, $colors['black'], $font, $servertext);
imagettftext($image, 12, 0, 71, 49, $colors['black'], $font, $servertext);
imagettftext($image, 12, 0, 72, 48, $colors['black'], $font, $servertext);
//Number of active players
imagettftext($image, 12, 0, 397, 50, $colors['black'], $font, $numplayers);
imagettftext($image, 12, 0, 398, 49, $colors['black'], $font, $numplayers);
imagettftext($image, 12, 0, 396, 49, $colors['black'], $font, $numplayers);
imagettftext($image, 12, 0, 397, 48, $colors['black'], $font, $numplayers);
//Number of alias's found on server
imagettftext($image, 10, 0, 188, 72, $colors['black'], $font, $numalias);
imagettftext($image, 10, 0, 187, 73, $colors['black'], $font, $numalias);
imagettftext($image, 10, 0, 187, 71, $colors['black'], $font, $numalias);
imagettftext($image, 10, 0, 186, 72, $colors['black'], $font, $numalias);
//Map name currently being played on server
imagettftext($image, 10, 0, 318, 72, $colors['black'], $font, $mapname);
imagettftext($image, 10, 0, 317, 73, $colors['black'], $font, $mapname);
imagettftext($image, 10, 0, 317, 71, $colors['black'], $font, $mapname);
imagettftext($image, 10, 0, 316, 72, $colors['black'], $font, $mapname);
//Do gaussian blur
//imageconvolution($image, $gaussian, 16, 0);
//Player meter
imagefilledrectangle($image, 7, $totalgraph, 23, 73, $colors[$usercolor]);
//Output all active text
//Output sv_hostname in color
$sx = 180;
for($i = 0, $size = sizeof($servernamepiece); $i < $size; ++$i)
{
//Get font bounding box info...
$bbox = imagettfbbox(13, 0, $font, $servernamepiece[$i]);
//Set font x position
$x = $bbox[0] + $sx;
//Draw this segment of sv_hostname in all black
imagettftext($image, 13, 0, $x, 22, $colors['white'], $font, $servernamepiece[$i]);
//Set new starting offset
$sx = $sx + $bbox[2] + 2;
}
//Server ip/port all black
imagettftext($image, 12, 0, 72, 49, $colors['white'], $font, $servertext);
//Number of active players
imagettftext($image, 12, 0, 397, 49, $colors['white'], $font, $numplayers);
//Number of alias's found on server
imagettftext($image, 10, 0, 187, 72, $colors['white'], $font, $numalias);
//Map currently being played on server
imagettftext($image, 10, 0, 317, 72, $colors['white'], $font, $mapname);
//Output phase 2 of static text, red post-blur face
imagettftext($image, 16, 0, 35, 22, $colors['black'], $font, $nametext);
imagettftext($image, 16, 0, 35, 49, $colors['black'], $font, $iptext);
imagettftext($image, 16, 0, 295, 49, $colors['black'], $font, $playertext);
imagettftext($image, 12, 0, 35, 72, $colors['black'], $font, $aliastext);
imagettftext($image, 12, 0, 265, 72, $colors['black'], $font, $maptext);
//Output image to browser
imageJPEG($image, NULL, 100);
//Destroy image to clear memory.
imageDestroy($image);
?>