/** * Render avatar */ private function render($data) { // Load Class and set parameters $chargen = new CharacterRender(); $chargen->action = CharacterRender::ACTION_IDLE; $chargen->direction = CharacterRender::DIRECTION_SOUTH; $chargen->body_animation = 0; $chargen->doridori = 0; $chargen->loadFromSqlData($data); // Load images $player = $chargen->render(); $border = imagecreatefrompng(Cache::$path . "avatar/data/border.png"); $background = imagecreatefromjpeg(Cache::$path . "avatar/data/background01.jpg"); $output = imagecreatetruecolor(128, 128); // Build image imagecopy($output, $background, 7, 7, 0, 0, 114, 114); imagecopy($output, $player, 7, 7, 35 + 7, 65 + 7, imagesx($player) - 14, imagesx($player) - 14); imagecopy($output, $border, 0, 0, 0, 0, 128, 128); // Add emblem if (!empty($data['emblem_data'])) { $binary = @gzuncompress(pack('H*', $data['emblem_data'])); if ($binary && ($emblem = imagecreatefrombmpstring($binary))) { imagecopy($output, $emblem, 128 - 10 - 24, 128 - 10 - 24, 0, 0, 24, 24); } } // Set color for text $name_color = imagecolorallocate($output, 122, 122, 122); $lvl_color = imagecolorallocate($output, 185, 109, 179); $status_color = $data['online'] ? imagecolorallocate($output, 59, 129, 44) : imagecolorallocate($output, 188, 98, 98); // Draw text imagestring($output, 1, 12, 12, strtoupper($data['name']), $name_color); imagestring($output, 1, 12, 25, $data['base_level'] . "/" . $data['job_level'], $lvl_color); imagestring($output, 1, 81, 12, $data['online'] ? "ONLINE" : "OFFLINE", $status_color); imagepng($output); }
/** * */ public function exportArchive() { $topDir = $this->sanitizePathName($this->loginAthenaGroup->serverName); $tmpDir = FLUX_DATA_DIR . '/tmp'; $tmpFile = tempnam($tmpDir, 'zip'); // Create zip archive. $zip = new ZipArchive(); $zip->open($tmpFile, ZIPARCHIVE::OVERWRITE); $zip->addEmptyDir($topDir); foreach ($this->athenaServers as $athenaServer) { $athenaDir = $this->sanitizePathName($athenaServer->serverName); $zip->addEmptyDir("{$topDir}/{$athenaDir}"); $sql = "SELECT name, emblem_data FROM {$athenaServer->charMapDatabase}.guild WHERE emblem_len > 0 ORDER BY name ASC"; $sth = $athenaServer->connection->getStatement($sql); $sth->execute(); $guilds = $sth->fetchAll(); if ($guilds) { foreach ($guilds as $guild) { $emblemData = @gzuncompress(pack('H*', $guild->emblem_data)); $emblemImage = imagecreatefrombmpstring($emblemData); ob_start(); imagepng($emblemImage); $data = ob_get_clean(); $emblemName = sprintf('%s.png', $this->sanitizePathName($guild->name)); $zip->addFromString("{$topDir}/{$athenaDir}/{$emblemName}", $data); } } } // Close archive. $zip->close(); // Send out appropriate HTTP headers. $filename = urlencode(sprintf('%s-%s-emblems.zip', strtolower($topDir), date('Ymd'))); header('Content-Type: application/zip'); header('Content-Length: ' . filesize($tmpFile)); header("Content-Disposition: attachment; filename={$filename}"); // Read contents of the file. readfile($tmpFile); // Remove temporary file. unlink($tmpFile); exit; }
/** * Render avatar */ private function render($data) { // Load Class and set parameters $chargen = new CharacterRender(); $chargen->action = CharacterRender::ACTION_SIT; $chargen->direction = CharacterRender::DIRECTION_SOUTHEAST; $chargen->body_animation = 0; $chargen->doridori = 0; $chargen->loadFromSqlData($data); // Build background $player = $chargen->render(); $output = imagecreatetruecolor(194, 110); $background = imagecreatefromjpeg(Cache::$path . "signature/data/background01.jpg"); imagecopy($output, $background, 2, 2, 0, 0, 190, 106); imagecopy($output, $player, 2, 2, 55, 80, imagesx($player) - 55 - 4, imagesx($player) - 90 - 4); // Add emblem if (!empty($data['emblem_data'])) { $binary = @gzuncompress(pack('H*', $data['emblem_data'])); if ($binary && ($emblem = imagecreatefrombmpstring($binary))) { imagecopy($output, $emblem, 194 - 6 - 24, 6, 0, 0, 24, 24); } } // Set color for text $name_color = imagecolorallocate($output, 254, 242, 183); $lvl_color = imagecolorallocate($output, 240, 143, 89); $status_color = $data['online'] ? imagecolorallocate($output, 125, 196, 126) : imagecolorallocate($output, 190, 83, 83); // Text align right func function imagestringright(&$img, $size, $x, $y, $str, $color) { imagestring($img, $size, $x - strlen($str) * imagefontwidth($size), $y, $str, $color); } // Draw text imagestringright($output, 2, 187, 69, $data['name'], $name_color); imagestringright($output, 2, 187, 82, $data['base_level'] . "/" . $data['job_level'], $lvl_color); imagestringright($output, 2, 187, 93, $data['online'] ? "Online" : "Offline", $status_color); // Cache the image imagepng($output); }
$filename = "{$dirname}/{$guildID}.png"; if (!is_dir($dirname)) { mkdir($dirname, 0777, true); } elseif (file_exists($filename) && time() - filemtime($filename) < $interval) { header("Content-Type: image/png"); header('Content-Length: ' . filesize($filename)); readfile($filename); exit; } } $db = $athenaServer->charMapDatabase; $sql = "SELECT emblem_len, emblem_data FROM {$db}.guild WHERE guild_id = ? LIMIT 1"; $sth = $athenaServer->connection->getStatement($sql); $sth->execute(array($guildID)); $res = $sth->fetch(); // 2-3. Apparently no emblem was found. if (!$res || !$res->emblem_len) { flux_display_empty_emblem(); } else { require_once 'functions/imagecreatefrombmpstring.php'; $data = @gzuncompress(pack('H*', $res->emblem_data)); $image = imagecreatefrombmpstring($data); header("Content-Type: image/png"); //header('Content-Length: '.strlen($data)); // -- Too unsafe; Can never be sure of the size. if ($interval) { imagepng($image, $filename); } imagepng($image); exit; } }
imagesetpixel($imres, $n++, $i, $pal[$p7]); imagesetpixel($imres, $n++, $i, $pal[$p8]); } } } } } } return $imres; } if (isset($_SESSION['emblems'])) { $emblems = $_SESSION['emblems']; if ($_GET['data'] && $emblems[$_GET['data']] != "") { $ebm = @gzuncompress(pack('H*', $emblems[$_GET['data']])); if (function_exists("gd_info")) { $im = imagecreatefrombmpstring($ebm); header('Content-Type: image/png'); imagepng($im); imagedestroy($im); } else { header('Content-Type: image/bitmap'); echo $ebm; } } } if (function_exists("gd_info")) { $im = imagecreate(24, 24); $bgc = imagecolorallocate($im, 0, 0, 0); imagefill($im, 0, 0, $bgc); header('Content-Type: image/png'); imagepng($im);
/** * Storing file in data folder (convert it if needed) * * @param {string} save to path * @param {string} file content * @return {string} content */ public static function store($path, $content) { $path = utf8_encode($path); $current_path = self::$path; $local_path = $current_path . str_replace('\\', '/', $path); $parent_path = preg_replace("/[^\\/]+\$/", '', $local_path); if (!file_exists($parent_path)) { if (!@mkdir($parent_path, 0777, true)) { Debug::write("Can't build path '{$parent_path}', need write permission ?", 'error'); return $content; } } if (!is_writable($parent_path)) { Debug::write("Can't write file to '{$parent_path}', need write permission.", 'error'); return $content; } // storing bmp images as png if (strtolower(pathinfo($path, PATHINFO_EXTENSION)) === 'bmp') { $img = imagecreatefrombmpstring($content); $path = str_ireplace('.bmp', '.png', $local_path); imagepng($img, $path); return file_get_contents($path); } // Saving file file_put_contents($local_path, $content); return $content; }