<?php
class Signatures {
private $sql = NULL;
private $settings = NULL;
private $func = NULL;
private $stats = NULL;
private $properties = Array();
private $types = Array("max", "med", "min", "x01");
private $image = NULL;
private $id = NULL;
public function __construct($id) {
$this->sql = new MySQL();
$this->settings = new Settings();
$this->func = new Functions();
$this->stats = new Stats($id);
$this->id = $id;
$this->load_signature_settings();
}
private function load_signature_settings() {
$data = $this->func->load_settings("signatures");
foreach ($this->types as $type) {
$this->properties[$type] = Array();
foreach ($data as $key => $value) {
if (substr($key, 0, strpos($key, "_")) == $type) {
$key = substr($key, strpos($key, "_")+1);
$this->properties[$type][$key] = $value;
}
}
}
}
private function check_rgb_color($string) {
$array = explode(",", $string);
for ($i = 0; $i < 3; $i++) {
if (isset($array[$i]) AND is_numeric($array[$i])) {
if ($array[$i] >= 0 OR $array[$i] <= 127) {
/* do nothing */
} else {
$array[$i] = 0;
}
} else {
$array[$i] = 0;
}
}
return $array;
}
private function create_background($type, $path, $width, $height) {
/* Variables */
$src = $path.'pattern/'.$this->properties[$type]['signature_pattern_filename'];
$bg_color = $this->check_rgb_color($this->properties[$type]['background_color']);
$alpha_start = $this->properties[$type]['background_alpha_start'];
$alpha_end = $this->properties[$type]['background_alpha_end'];
$offset = $this->properties[$type]['background_offset'];
/* Create the picture */
$this->image = imagecreatetruecolor($width, $height);
$pattern = imagecreatefrompng($src);
imagecopyresampled($this->image, $pattern, 0, 0, 0, 0, $width, $height, $width, $height);
/* Create the background gradient */
$alpha_step = ($alpha_end - $alpha_start) / ($width - $offset);
for ($i = 0; $i < ($width - $offset); $i++) {
$color = imagecolorallocatealpha($this->image, trim($bg_color[0]), trim($bg_color[1]), trim($bg_color[2]), ($i*$alpha_step)+$alpha_start);
imageline($this->image, $i, 0, $i, $height, $color);
}
}
private function create_rankicon($path, $type) {
$rank = $this->stats->get('player', 'rank');
if ($type == "max" OR $type == "x01") {
$width = 90;
$x = 20;
$y = 10;
}
if ($type == "med") {
$width = 60;
$x = 15;
$y = 10;
}
if ($type == "min") {
$width = 30;
$x = 10;
$y = 5;
}
$src = "../stylesheets/images/".$rank->img_large;
$icon = imagecreatefrompng($src);
imagecopyresampled($this->image, $icon, $x, $y, 0, 0, $width, $width, 256, 256);
}
private function create_text($path, $type) {
/* Variables */
$font_file = $path.'fonts/'.$this->properties[$type]['font_filename'];
$size = $this->properties[$type]['font_size'];
$color = $this->check_rgb_color($this->properties[$type]['font_color']);
$player = $this->stats->get('player');
$scores = $this->stats->get('scores');
$global = $this->stats->get('global');
/* Allocate image colors */
$font_color = imagecolorallocate($this->image, trim($color[0]), trim($color[1]), trim($color[2]));
/* Create the texts */
if ($type == "max") {
$size1 = $size;
$size2 = round($size * 1.5);
$size3 = $size2 + 10;
$size4 = $size3 + 25;
$size5 = $size + 6;
/* Name & Rank */
$rankname = $player['rank']->name;
$pos = imagefttext($this->image, $size2, 0, 130, ($size3) , $font_color, $font_file, $player['name']);
$pos = imagefttext($this->image, $size1, 0, ($pos[2] + 10), ($size3), $font_color, $font_file, $rankname);
$x = 130;
/* Label 1 */
$pos = imagefttext($this->image, $size1, 0, $x, ($size4) , $font_color, $font_file, "Score:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "Kills:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "Deaths:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "Dogtags:");
$x += 60;
/* Values 1 */
$pos = imagefttext($this->image, $size1, 0, $x, ($size4) , $font_color, $font_file, $scores['score']);
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $global['kills']);
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $global['deaths']);
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $global['dogtags']);
$x += 90;
/* Label 2 */
$pos = imagefttext($this->image, $size1, 0, $x, ($size4) , $font_color, $font_file, "SPM:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "KPM:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "KDR:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "Time:");
$x += 40;
/* Values 2 */
$pos = imagefttext($this->image, $size1, 0, $x, ($size4) , $font_color, $font_file, $this->stats->get('scores', 'score', Array('ratio', ($global['time'] / 60), 0), false));
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $this->stats->get('global', 'kills', Array('ratio', ($global['time'] / 60), 2), false));
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $this->stats->get('global', 'kills', Array('ratio', ($global['deaths']), 2), false));
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $this->stats->get('global', 'time', Array('time', 0, 'dynamic'), false));
}
if ($type == "med") {
$size1 = $size;
$size2 = round($size * 1.5);
$size3 = $size2 + 10;
$size4 = $size3 + 20;
$size5 = $size + 6;
/* Name & Rank */
$rankname = $player['rank']->name;
$pos = imagefttext($this->image, $size2, 0, 90, ($size3) , $font_color, $font_file, $player['name']);
$pos = imagefttext($this->image, $size1, 0, ($pos[2] + 10), ($size3), $font_color, $font_file, $rankname);
$x = 90;
/* Label 1 */
$pos = imagefttext($this->image, $size1, 0, $x, ($size4) , $font_color, $font_file, "Score:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "Kills:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "Dogtags:");
$x += 55;
/* Values 1 */
$pos = imagefttext($this->image, $size1, 0, $x, ($size4) , $font_color, $font_file, $scores['score']);
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $global['kills']);
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $global['dogtags']);
$x += 70;
/* Label 2 */
$pos = imagefttext($this->image, $size1, 0, $x, ($size4) , $font_color, $font_file, "SPM:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "KPM:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "KDR:");
$x += 30;
/* Values 2 */
$pos = imagefttext($this->image, $size1, 0, $x, ($size4) , $font_color, $font_file, $this->stats->get('scores', 'score', Array('ratio', ($global['time'] / 60), 0), false));
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $this->stats->get('global', 'kills', Array('ratio', ($global['time'] / 60), 2), false));
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $this->stats->get('global', 'kills', Array('ratio', ($global['deaths']), 2), false));
}
if ($type == "min") {
$size1 = $size;
$size2 = round($size * 1.4);
$size3 = $size2 + 7;
$size4 = $size3 + 15;
$size5 = round($size * 1.2);
/* Name & Rank */
$rankname = $player['rank']->name;
$pos = imagefttext($this->image, $size2, 0, 50, ($size3), $font_color, $font_file, $player['name']);
$pos = imagefttext($this->image, $size1, 0, ($pos[2] + 10), ($size3), $font_color, $font_file, $rankname);
$x = 50;
/* Values 1 */
$pos = imagefttext($this->image, $size5, 0, $x, $size4, $font_color, $font_file, "SPM:");
$pos = imagefttext($this->image, $size5, 0, $pos[2] + 5, $size4, $font_color, $font_file, $this->stats->get('scores', 'score', Array('ratio', ($global['time'] / 60), 0), false));
$pos = imagefttext($this->image, $size5, 0, $pos[2] + 10, $size4, $font_color, $font_file, "KPM:");
$pos = imagefttext($this->image, $size5, 0, $pos[2] + 5, $size4, $font_color, $font_file, $this->stats->get('global', 'kills', Array('ratio', ($global['time'] / 60), 2), false));
$pos = imagefttext($this->image, $size5, 0, $pos[2] + 10, $size4, $font_color, $font_file, "KDR:");
$pos = imagefttext($this->image, $size5, 0, $pos[2] + 5, $size4, $font_color, $font_file, $this->stats->get('global', 'kills', Array('ratio', ($global['deaths']), 2), false));
}
if ($type == "x01") {
$size1 = $size;
$size2 = round($size * 1.5);
$size3 = $size2 + 10;
$size4 = $size3 + 25;
$size5 = $size + 6;
/* Name & Rank */
$rankname = $player['rank']->name;
$pos = imagefttext($this->image, $size2, 0, 130, ($size3) , $font_color, $font_file, $player['name']);
$pos = imagefttext($this->image, $size1, 0, ($pos[2] + 10), ($size3), $font_color, $font_file, $rankname);
$x = 130;
/* Label 1 */
$pos = imagefttext($this->image, $size1, 0, $x, ($size4) , $font_color, $font_file, "Score:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "Kills:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "Deaths:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "Dogtags:");
$x += 60;
/* Values 1 */
$pos = imagefttext($this->image, $size1, 0, $x, ($size4) , $font_color, $font_file, $scores['score']);
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $global['kills']);
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $global['deaths']);
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $global['dogtags']);
$x += 90;
/* Label 2 */
$pos = imagefttext($this->image, $size1, 0, $x, ($size4) , $font_color, $font_file, "SPM:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "KPM:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "KDR:");
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, "Time:");
$x += 40;
/* Values 2 */
$pos = imagefttext($this->image, $size1, 0, $x, ($size4) , $font_color, $font_file, $this->stats->get('scores', 'score', Array('ratio', ($global['time'] / 60), 0), false));
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $this->stats->get('global', 'kills', Array('ratio', ($global['time'] / 60), 2), false));
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $this->stats->get('global', 'kills', Array('ratio', ($global['deaths']), 2), false));
$pos = imagefttext($this->image, $size1, 0, $x, ($pos[1] + $size5), $font_color, $font_file, $this->stats->get('global', 'time', Array('time', 0, 'dynamic'), false));
/* Favourites */
$sigwidth = $this->properties[$type]['signature_width'];
$sigheight = $this->properties[$type]['signature_height'];
$padding = 15; // Abstand zur Seite
$margin = -10; // Abstand nach oben
$width = 180; // Breite des Fav-Pics
$height = $width * 154 / 256; // Höhe des Fav-Pics
$gap = $sigwidth - (2*$width + 2*$padding); // Breite der Lücke zwischen beiden Pics
$weapon = $this->stats->format('weapons', 'favs');
$src = imagecreatefrompng("../stylesheets/images/".$weapon['pic']);
imagecopyresampled($this->image, $src, $padding, ($pos[1] + $margin), 0, 0, $width, $height, 256, 154);
imagefttext($this->image, $size1*0.9, 0, $padding, ($sigheight - $padding), $font_color, $font_file, "Favourite Weapon: ".$weapon['raw']);
$vehicle = $this->stats->format('vehicles', 'favs');
$src = imagecreatefrompng("../stylesheets/images/".$vehicle['pic']);
imagecopyresampled($this->image, $src, ($padding + $width + $gap), ($pos[1] + $margin), 0, 0, $width, $height, 254, 153);
$textwidth = imagettfbbox($size1*0.9, 0, $font_file, "Favourite Vehicle: ".$vehicle['raw']);
imagefttext($this->image, $size1*0.9, 0, ($sigwidth - $textwidth[4] - $padding - 5), ($sigheight - $padding), $font_color, $font_file, "Favourite Vehicle: ".$vehicle['raw']);
}
}
private function create_picture($path, $type) {
/* Variables */
$filename = $this->id."_".$type.".png";
$filename = $filename;
/* Create the picture */
imagepng($this->image, $path.$filename);
imagedestroy($this->image);
}
public function create_signature() {
foreach ($this->types as $type) {
$path = "../signatures/";
$width = $this->properties[$type]['signature_width'];
$height = $this->properties[$type]['signature_height'];
$this->create_background($type, $path, $width, $height);
$this->create_rankicon($path, $type);
$this->create_text($path, $type);
$this->create_picture($path, $type);
}
return true;
}
}
?>