function RenderName($name, $x, $y)
{
    global $character_id;
    global $im;
    global $font;
    global $font_size;
    global $__database;
    global $guild_info_location;
    $background = imagecolorallocatealpha($im, 0, 0, 0, 33);
    $fontcolor = imagecolorallocate($im, 255, 255, 255);
    $startWidth = $x - calculateWidth($name) / 2;
    $endWidth = $x + calculateWidth($name) / 2;
    DrawNameBox($im, $startWidth, $y - 17, $endWidth - 1, $y - 2, $background);
    ImageTTFText($im, $font_size, 0, $startWidth + 3, $y - 5, $fontcolor, $font, $name);
    $q = $__database->query("SELECT g.name, g.emblem_bg, g.emblem_bg_color, g.emblem_fg, g.emblem_fg_color FROM guild_members c INNER JOIN guilds g ON g.id = c.guild_id WHERE c.character_id = " . $character_id);
    if ($q->num_rows == 1) {
        $res = $q->fetch_array();
        $name = $res[0];
        $hasemblem = $res[1] != 0 || $res[2] != 0 || $res[3] != 0 || $res[4] != 0 ? true : false;
        $startWidth = $x - calculateWidth($name) / 2;
        $endWidth = $x + calculateWidth($name) / 2;
        DrawNameBox($im, $startWidth, $y, $endWidth - 1, $y + 15, $background);
        ImageTTFText($im, $font_size, 0, $startWidth + 2, $y + 12, $fontcolor, $font, $name);
        ImageTTFText($im, $font_size, 0, $startWidth + 3, $y + 12, $fontcolor, $font, $name);
        // Boldness
        if ($hasemblem) {
            if ($res[1] != 0 || $res[2] != 0) {
                add_image($guild_info_location . '/BackGround/0000' . $res[1] . '/' . $res[2] . '.png', $startWidth - 18, $y + 1);
            }
            if ($res[3] != 0 || $res[4] != 0) {
                $name = "";
                $sort = floor($res[3] / 1000);
                if ($sort == 2) {
                    $name = "Animal";
                } elseif ($sort == 3) {
                    $name = "Plant";
                } elseif ($sort == 4) {
                    $name = "Pattern";
                } elseif ($sort == 5) {
                    $name = "Letter";
                } elseif ($sort == 9) {
                    $name = "Etc";
                }
                add_image($guild_info_location . '/Mark/' . $name . '/0000' . $res[3] . '/' . $res[4] . '.png', $startWidth - 17, $y + 2);
            }
        }
    }
}
$q2->free();
$image = imagecreatetruecolor(271, 162);
imagealphablending($image, false);
imagesavealpha($image, true);
$bg_image = imagecreatefrompng("../inc/img/char_bg.png");
imagecopyresampled($image, $bg_image, 0, 0, 0, 0, 271, 386, 271, 386);
imagealphablending($image, true);
// LOAD CHARACTER
$charpos_x = -4;
$charpos_y = 15;
$character_image = LoadPNG("http://" . $domain . "/avatar/" . $charname);
//$character_image = LoadPNG("http://mapler.me/avatar/".$charname);
imagecopyresampled($image, $character_image, $charpos_x, $charpos_y, 0, 0, 128, 128, 128, 128);
// SET NAMETAG
$name = $row['name'];
$x = $charpos_x + 128 / 2;
$y = $charpos_y + 15 + 96;
$startWidth = $x - calculateWidth($name) / 2;
$endWidth = $x + calculateWidth($name) / 2;
ImageTTFText($image, $font_size, 0, $startWidth + 3, $y - 5, imagecolorallocate($image, 255, 255, 255), $font, $name);
$base_x = 152;
$base_y = 55;
$step = 18;
ImageTTFText($image, 9, 0, $base_x, $base_y + $step * 0, imagecolorallocate($image, 0, 0, 0), $font, $row['level']);
ImageTTFText($image, 9, 0, $base_x, $base_y + $step * 1, imagecolorallocate($image, 0, 0, 0), $font, GetJobname($row['job']));
ImageTTFText($image, 9, 0, $base_x, $base_y + $step * 2, imagecolorallocate($image, 0, 0, 0), $font, $row['fame']);
ImageTTFText($image, 9, 0, $base_x, $base_y + $step * 3, imagecolorallocate($image, 0, 0, 0), $font, $row['guildname']);
//ImageTTFText($image, 9, 0, $base_x, $base_y + ($step * 4), imagecolorallocate($image, 0, 0, 0), $font, "HAXCLANZ");
SaveCacheImage($internal_id, 'info', $image, $id);
imagepng($image);
imagedestroy($image);