Language: EN FR PT ES NL DE SV RU
<?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 imagecreatetruecolor46880 );
            
            
//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$lvlshotimage000$lvlshotsy46880$lvlshottx$lvlshotly);
            
            
//Output jpeg to bannerfile for map
            
imagejpeg($bannerout$bannerfile100);
            
            
//Close both images
            
imagedestroy ($bannerout);
            
imagedestroy ($lvlshotimage);
        }
    }
    
    
//Create the base image from the default banner
    
$preimage imageCreateFromJPEG($bannerfile);
    
$superimp imagecreatetruecolor46880 );

    
$precolors = array(
        
'black' => imagecolorallocate($superimp000),
        
'white' => imageColorAllocate($superimp255255255),
        
'grey' => imageColorAllocate($superimp128128128),
    );
    
    
//Turn on anti-aliasing functions for the image
    //imageantialias($preimage, true);
    //imageantialias($superimp, true);
    
    
imagefill($superimp00$precolors['grey']);
    
    
imagefilledrectangle($superimp552575$precolors['black']);
    
imagefilledrectangle($superimp30346327$precolors['white']);
    
imagefilledrectangle($superimp303028553$precolors['white']);
    
imagefilledrectangle($superimp2903046353$precolors['white']);
    
    
imagecopymerge($preimage$superimp00004688033);
    
    
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($sv035);
    
    
//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], 01);
        
        
//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 = (+ (($percentplayers) * 66));
    
$numplayers $totalplayers ' / ' $totalslots;
        
    
//gaussian blur matrix
    
$gaussian = array(array(1.02.01.0), array(2.04.02.0), array(1.02.01.0));
    
    
//Background for player meter

    //Output phase 1 of static text, white blurred background
    
imagettftext($image1603622$colors[$usercolor], $font$nametext);
    
imagettftext($image1603523$colors[$usercolor], $font$nametext);
    
imagettftext($image1603422$colors[$usercolor], $font$nametext);
    
imagettftext($image1603521$colors[$usercolor], $font$nametext);
    
    
imagettftext($image1603550$colors[$usercolor], $font$iptext);
    
imagettftext($image1603649$colors[$usercolor], $font$iptext);
    
imagettftext($image1603449$colors[$usercolor], $font$iptext);
    
imagettftext($image1603548$colors[$usercolor], $font$iptext);
    
    
imagettftext($image16029649$colors[$usercolor], $font$playertext);
    
imagettftext($image16029550$colors[$usercolor], $font$playertext);
    
imagettftext($image16029548$colors[$usercolor], $font$playertext);
    
imagettftext($image16029449$colors[$usercolor], $font$playertext);
    
    
imagettftext($image1203573$colors[$usercolor], $font$aliastext);
    
imagettftext($image1203672$colors[$usercolor], $font$aliastext);
    
imagettftext($image1203472$colors[$usercolor], $font$aliastext);
    
imagettftext($image1203571$colors[$usercolor], $font$aliastext);
    
    
imagettftext($image12026672$colors[$usercolor], $font$maptext);
    
imagettftext($image12026573$colors[$usercolor], $font$maptext);
    
imagettftext($image12026571$colors[$usercolor], $font$maptext);
    
imagettftext($image12026472$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(130$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($image130$x23$colors[$color], $font$servernamepiece[$i]);
        
imagettftext($image130, ($x 1), 22$colors[$color], $font$servernamepiece[$i]);
        
imagettftext($image130, ($x 1), 22$colors[$color], $font$servernamepiece[$i]);
        
imagettftext($image130$x21$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($image1207250$colors['black'], $font$servertext);
    
imagettftext($image1207349$colors['black'], $font$servertext);
    
imagettftext($image1207149$colors['black'], $font$servertext);
    
imagettftext($image1207248$colors['black'], $font$servertext);
    
    
//Number of active players
    
imagettftext($image12039750$colors['black'], $font$numplayers);
    
imagettftext($image12039849$colors['black'], $font$numplayers);
    
imagettftext($image12039649$colors['black'], $font$numplayers);
    
imagettftext($image12039748$colors['black'], $font$numplayers);
    
    
//Number of alias's found on server
    
imagettftext($image10018872$colors['black'], $font$numalias);
    
imagettftext($image10018773$colors['black'], $font$numalias);
    
imagettftext($image10018771$colors['black'], $font$numalias);
    
imagettftext($image10018672$colors['black'], $font$numalias);
    
    
//Map name currently being played on server
    
imagettftext($image10031872$colors['black'], $font$mapname);
    
imagettftext($image10031773$colors['black'], $font$mapname);
    
imagettftext($image10031771$colors['black'], $font$mapname);
    
imagettftext($image10031672$colors['black'], $font$mapname);
    
    
//Do gaussian blur
    //imageconvolution($image, $gaussian, 16, 0);
    
    //Player meter
    
imagefilledrectangle($image7$totalgraph2373$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(130$font$servernamepiece[$i]);
        
        
//Set font x position
        
$x $bbox[0] + $sx;
        
        
//Draw this segment of sv_hostname in all black
        
imagettftext($image130$x22$colors['white'], $font$servernamepiece[$i]);
        
        
//Set new starting offset
        
$sx $sx $bbox[2] + 2;
    }

    
//Server ip/port all black
    
imagettftext($image1207249$colors['white'], $font$servertext);
    
    
//Number of active players
    
imagettftext($image12039749$colors['white'], $font$numplayers);
    
    
//Number of alias's found on server
    
imagettftext($image10018772$colors['white'], $font$numalias);
    
    
//Map currently being played on server
    
imagettftext($image10031772$colors['white'], $font$mapname);
    
    
//Output phase 2 of static text, red post-blur face
    
imagettftext($image1603522$colors['black'], $font$nametext);
    
imagettftext($image1603549$colors['black'], $font$iptext);
    
imagettftext($image16029549$colors['black'], $font$playertext);
    
imagettftext($image1203572$colors['black'], $font$aliastext);
    
imagettftext($image12026572$colors['black'], $font$maptext);
    
    
//Output image to browser
    
imageJPEG($imageNULL100);
    
    
//Destroy image to clear memory.
    
imageDestroy($image);
    
?>