$config = array();
$config['ip'] = '178.77.66.123';
$config['queryport'] = '######';
$config['serverport'] = '9987';
$config['loginname'] = '######';
$config['loginpass'] = '######';
$config['displayname'] = 'TS3-UserInfo-Bot';
require_once('libraries/TeamSpeak3/TeamSpeak3.php');
TeamSpeak3::init();
$ts3 = TeamSpeak3::factory("serverquery://".$config['loginname'].":".$config['loginpass']."@".$config['ip'].":".$config['queryport']."/?server_port=".$config['serverport']."&nickname=".urlencode($config['displayname'])."");
$lastConnected = "";
foreach ($ts3->clientList(array('client_type' => 0)) as $client) {
if (!is_object($lastConnected)) {
$lastConnected = $client;
} else if ($client->client_lastconnected > $lastConnected->client_lastconnected) {
$lastConnected = $client;
$avatar = file_get_contents('img/'.$client->client_database_id);
preg_match('/\A(?:(\xff\xd8\xff)|(GIF8[79]a)|(\x89PNG\x0d\x0a)|(BM)|(\x49\x49(\x2a\x00|\x00\x4a))|(FORM.{4}ILBM))/', $avatar, $matches);
$type = array(
1 => "image/jpeg",
2 => "image/gif",
3 => "image/png",
4 => "image/x-windows-bmp",
5 => "image/tiff",
6 => "image/x-ilbm",
);
switch ($type[count($matches)-1])
{
case 'image/jpeg':
$avatar = imagecreatefromjpeg('img/'.$client->client_database_id);
break;
case 'image/gif':
$avatar = imagecreatefromgif('img/'.$client->client_database_id);
break;
case 'image/png':
$avatar = imagecreatefrompng('img/'.$client->client_database_id);
break;
default:
$default = true;
$avatar = imagecreatefrompng('img/user.png'); //default Bild
}
}
}
$fontface7= "/var/www/vhosts/gamingteam.de/httpdocs/ts3/banner/font/arialbd.ttf";
$fontsize7 = 10;
$text7 = $lastConnected->client_nickname;
$left7 = 7;
$top7 = 120;
$image = imagecreatefrompng("images/banner-layout3.png");
$imagesize = getimagesize("images/banner-layout3.png");
$blue = ImageColorAllocate($image, 0,156,255);
$weiss = ImageColorAllocate($image, 255,255,255);
imagettftext($image, $fontsize7, 0, $left7, $top7, $blue, $fontface7, $text7);
header("content-type: image/png");
// Bildpfad
$bildpfad1 = "img/banner-layout3.png";
// Speicher in Datei
imagepng($image, $bildpfad1);
// Cache leeren
imagedestroy($image);
$tsbanner = imageCreateFromPNG("img/banner-layout3.png");
function f($image, $boxWidth, $boxHeight)
{
$imageWidth = imagesx($image);
$imageHeight = imagesy($image);
$sfw = $imageWidth / $boxWidth;
$sfh = $imageHeight / $boxHeight;
if ($sfw < $sfh) {
$tmpBoxWidth = $boxWidth * $sfw;
$tmpBoxHeight = $boxHeight * $sfw;
} else {
$tmpBoxWidth = $boxWidth * $sfh;
$tmpBoxHeight = $boxHeight * $sfh;
}
$dstim = imagecreatetruecolor($tmpBoxWidth, $tmpBoxHeight);
if ($sfw < $sfh) {
imagecopy($dstim, $image, 0, 0, 0, ($imageHeight - $tmpBoxHeight) / 2, $tmpBoxWidth, $tmpBoxHeight);
} else {
imagecopy($dstim, $image, 0, 0, ($imageWidth - $tmpBoxWidth) / 2, 0, $tmpBoxWidth, $tmpBoxHeight);
}
$dstim2 = imagecreatetruecolor($boxWidth, $boxHeight);
imagecopyresampled($dstim2, $dstim, 0, 0, 0, 0, $boxWidth, $boxHeight, $tmpBoxWidth, $tmpBoxHeight);
return $dstim2;
}
$display = function ($image) {
ob_start();
imagejpeg($image);
$data = ob_get_clean();
return sprintf(
'<img src="data:image/jpeg;base64,%s">',
base64_encode($data)
);
};
$avatarWidth = 64;
$avatarHeight = 64;
$avatarSourceData = file_get_contents($avatar);
$avatarSourceImage = imagecreatefromstring($avatarSourceData);
$avatarImage = f($avatarSourceImage, $avatarWidth, $avatarHeight);
$backdropData = file_get_contents('img/banner-layout3.png');
$backdropImage = imagecreatefromstring($backdropData);
$combinedImage = imagecreatefromstring($backdropData);
imagecopy($combinedImage, $avatarImage, 7, 42, 0, 0, $avatarWidth, $avatarHeight);
// Bildpfad
$bildpfad2 = "/var/www/vhosts/gamingteam.de/httpdocs/ts3/banner/banner.png";
// Speicher in Datei
imagepng($tsbanner, $bildpfad2);
// Cache leeren
imagedestroy($tsbanner);