Index: createbanner.php =================================================================== --- createbanner.php (revision 340) +++ createbanner.php (revision 312) @@ -40,270 +40,73 @@ * */ -define('FONT_FILE', dirname(__FILE__) . '/resources/fonts/visitor/visitor.ttf'); -define('BACKGROUND_FILE', dirname(__FILE__) . '/resources/backgrounds/default.png'); -define('TIMEZONE', 'Europe/Paris'); - -date_default_timezone_set(TIMEZONE); - -require_once dirname(dirname(__FILE__)) . '/db/mysql.php'; - -/** - * - * @todo Update the position alignment management. - * @author Greg - * - */ -class Nova_Image_Block_Image_Png -{ - private $_format = NULL; - private $_mime = NULL; - - const COLOR_RED = 'red'; - const COLOR_GREEN = 'green'; - const COLOR_BLUE = 'blue'; - - const POSITION_LEFT = 0x01; - const POSITION_RIGHT = 0x02; - const POSITION_CENTER = 0x03; - - const POSITION_TOP = 0x10; - const POSITION_BOTTOM = 0x20; - const POSITION_MIDDLE = 0x30; +define('INSIDE' , true); +define('INSTALL' , false); +require_once dirname(__FILE__) .'/../common.php'; - const POSITION_DEFAULT = 0x11; +includeLang('overview'); - private $_texts = array(); - private $_background = NULL; - private $_font = NULL; - - public function __construct() - { - $this->_setMime('image/png'); - $this->_setFormat('png'); - } - - protected function _getFormat() - { - return $this->_format; - } - - protected function _setFormat($format) - { - $this->_format = $format; - - return $this; - } - - protected function _getMime() - { - return $this->_mime; - } - - protected function _setMime($mime) - { - $this->_mime = $mime; - - return $this; - } - - public function getHeaders() - { - return array( - 'Content-Type' => $this->_getMime() - ); - } - - public function addText($content, $fontSize, $fontFile, $positionAbscix, $positionOrdinates, $angle, Array $color, $alignment = self::POSITION_DEFAULT) - { - $this->_texts[] = array( - 'content' => $content, - 'color' => $color, - 'sizes' => $this->_getTextPositions($content, $fontSize, $fontFile, $positionAbscix, $positionOrdinates, $angle, $alignment), - 'font_size' => $fontSize, - 'font_file' => $fontFile, - ); - - return $this; - } - - public function _getTextPositions($textContent, $fontSize, $fontFile, $positionAbscix, $positionOrdinates, $angle = 0, $alignment = self::POSITION_DEFAULT) - { - $dimensions = imageFtbBox($fontSize, $angle, $fontFile, $textContent); - $width = $dimensions[2] - $dimensions[0]; - $height = $dimensions[1] - $dimensions[7]; - - switch ($alignment & 0x7) { - case self::POSITION_CENTER: - $positionAbscix -= ceil($width / 2); - break; - - case self::POSITION_RIGHT: - $positionAbscix -= $width; - break; - - case self::POSITION_LEFT: - default: - break; - } - - switch ($alignment & 0x70) { - case self::POSITION_MIDDLE: - $positionOrdinates -= ceil($height / 2); - break; - - case self::POSITION_TOP: - $positionOrdinates -= $height; - break; - - case self::POSITION_BOTTOM: - default: - $width = 0; - $height = 0; - break; - } - - - return array( - 'abscix' => $positionAbscix, - 'ordinate' => $positionOrdinates, - 'alignment' => $alignment, - 'width' => $width, - 'height' => $height, - 'angle' => $angle - ); - } - - public function setBackground($backgroundImage) - { - $this->_background = $backgroundImage; - - return $this; - } - - public function setFont($fontFile) - { - $this->_font = $fontFile; - - return $this; - } - - public function render() - { - ob_start(); - if (!is_null($this->_background)) { - $gdHandler = imageCreateFromPng($this->_background); - } else { - $gdHandler = imageCreateTrueColor(); - } - - foreach ($this->_texts as $text) { - $color = imageColorAllocate( - $gdHandler, - $text['color'][self::COLOR_RED], - $text['color'][self::COLOR_GREEN], - $text['color'][self::COLOR_BLUE] - ); - - switch ($text['sizes']['alignment'] & 0x0F) { - case self::POSITION_CENTER: - $text['sizes']['abscix'] -= floor(imageSX($gdHandler) / 2); - break; - - case self::POSITION_RIGHT: - $text['sizes']['abscix'] = imageSX($gdHandler) - ($text['sizes']['abscix'] + $text['sizes']['width']) -10; - break; - - case self::POSITION_LEFT: - default: - break; - } - - $imageText = imageTtfText( - $gdHandler, - $text['font_size'], - $text['sizes']['angle'], - $text['sizes']['abscix'], - $text['sizes']['ordinate'], - $color, - $text['font_file'], - $text['content'] - ); - } - - imagePng($gdHandler); - imageDestroy($gdHandler); - - $imageData = ob_get_contents(); - ob_end_clean(); - - return $imageData; - } +// Function to center text in the created banner +function CenterTextBanner($z,$y,$zone) { + $a = strlen($z); + $b = imagefontwidth($y); + $c = $a*$b; + $d = $zone-$c; + $e = $d/2; + return $e; } -if (isset($_GET['id'])) { - $id = (int) $_GET['id']; -} else { - header('HTTP/1.1 412 Precondition Failed'); - die(); -} +extract($_GET); +if (isset($id)) { + // Parameters + header ("Content-type: image/png"); + $image = imagecreatefrompng($game_config['banner_source_post']); + $date = date("d/m/y"); -$textColor = array( - Nova_Image_Block_Image_Png::COLOR_RED => 0xEF, - Nova_Image_Block_Image_Png::COLOR_GREEN => 0xEF, - Nova_Image_Block_Image_Png::COLOR_BLUE => 0xEF - ); + // Querys + $Player = doquery("SELECT * FROM {{table}} WHERE `id` = '".$id."';", 'users', true); + $Stats = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '".$id."';", 'statpoints', true); + $Planet = doquery("SELECT * FROM {{table}} WHERE `id_owner` = '".$id."' AND `planet_type` = '1' LIMIT 1;", 'planets', true); -$sql = << 'XNova:Legacies', - 'date' => date('d M Y') - ), - doquery($sql, '', true) - ); + // Colors + $color = "FFFFFF"; + $red = hexdec(substr($color,0,2)); + $green = hexdec(substr($color,2,4)); + $blue = hexdec(substr($color,4,6)); + $select = imagecolorallocate($image,$red,$green,$blue); -$image = new Nova_Image_Block_Image_Png(); -$image - ->setBackground(BACKGROUND_FILE) - ->addText($data['game_name'], 24, FONT_FILE, 5, 37, 0, $textColor) - ->addText($data['username'], 24, FONT_FILE, 250, 37, 0, $textColor) + // Display + // Univers name + imagestring($image, 1, CenterTextBanner($b_univ,1,653), 57, $b_univ, $select); + // Today date + imagestring($image, 1, CenterTextBanner($date,1,653), 65, $date, $select); + // Player name + imagestring($image, 3, 15, 12, $b_user, $select); + // Player b_planet + imagestring($image, 3, 150, 12, "".$b_planet." ".$b_xyz."", $select); + // Player level + imagestring($image, 10, CenterTextBanner($b_lvl,10,795), 40, $b_lvl, $select); + // Player stats + imagestring($image, 2, 15, 38, $b_build, $select); + imagestring($image, 2, 15, 55, $b_fleet, $select); + imagestring($image, 2, 150, 38, $b_search, $select); + imagestring($image, 2, 150, 55, $b_total, $select); - ->addText('Batiments:', - 14, FONT_FILE, 5, 50, 0, $textColor) - ->addText(number_format($data['build_points'], 0, ',', '.'), - 14, FONT_FILE, 100, 50, 0, $textColor) - ->addText('Flottes:', - 14, FONT_FILE, 5, 70, 0, $textColor) - ->addText(number_format($data['fleet_points'], 0, ',', '.'), - 14, FONT_FILE, 100, 70, 0, $textColor) - - ->addText('Technologies:', - 14, FONT_FILE, 205, 50, 0, $textColor) - ->addText(number_format($data['tech_points'], 0, ',', '.'), - 14, FONT_FILE, 320, 50, 0, $textColor) - ->addText('Total:', - 14, FONT_FILE, 205, 70, 0, $textColor) - ->addText(number_format($data['total_points'], 0, ',', '.'), - 14, FONT_FILE, 320, 70, 0, $textColor) -; - -foreach ($image->getHeaders() as $headerName => $headerValue) { - header(sprintf('%s: %s', $headerName, $headerValue)); + // Creat and delete banner + imagepng ($image); + imagedestroy ($image); } -echo $image->render(); +?> \ No newline at end of file