//create rglove1
    $rglove1_location = $characterwz . "/Glove/0" . $glove . ".img/stand1.0.rGlove.png";
    add_image($rglove1_location, $mainx + $rglove1x, $necky + $rglove1y);
}
// Create weaponOverGlove
if ($weaponz == 'weaponOverGlove' || $weaponz == 'weaponOverHand') {
    if (isset($wepnum)) {
        $wep_location = $characterwz . "/Weapon/0" . $nxwep . ".img/" . $wepnum . ".stand" . $stand . ".0.weapon.png";
    } else {
        $wep_location = $characterwz . "/Weapon/0" . $nxwep . ".img/stand" . $stand . ".0.weapon.png";
    }
    add_image($wep_location, $wepx + $weaponx, $wepy + $weapony);
}
// Render name
if (isset($_GET['show_name'])) {
    RenderName($character_data['name'], $image_width / 2, $mainy + 71);
}
if (!isset($_GET['NO_CACHING'])) {
    SaveCacheImage($internal_id, $image_mode, $im, $id);
}
imagepng($im);
imagedestroy($im);
// Function to phrase data into an array
function get_data($itemid)
{
    return GetItemWZInfo($itemid, CURRENT_LOCALE);
}
// Function to add element to the image
function add_image($location, $x, $y)
{
    global $im;
        }
        if (isset($data_buffer['extra_layers'][-1])) {
            foreach ($data_buffer['extra_layers'][-1] as $imginfo) {
                DrawImage($imginfo[0], $imginfo[1], $imginfo[2], false, $temp_image);
            }
        }
        imagecopy($temp_image, $im, 0, 0, 0, 0, $image_width, $result_height);
        if (isset($data_buffer['extra_layers'][1])) {
            foreach ($data_buffer['extra_layers'][1] as $imginfo) {
                DrawImage($imginfo[0], $imginfo[1], $imginfo[2], false, $temp_image);
            }
        }
        if (isset($data_buffer['extra_layers'][2])) {
            foreach ($data_buffer['extra_layers'][2] as $imginfo) {
                DrawImage($imginfo[0], $imginfo[1], $imginfo[2], false, $temp_image);
            }
        }
        $im = $temp_image;
    }
    // Change mainx/y
    $imageoptions['mainx'] = imagesx($im) / 2;
    $imageoptions['mainy'] = imagesy($im) / 2 + 18;
    // Render name
    if ($imageoptions['show-name']) {
        RenderName($options['name'], $imageoptions['mainx'], $imageoptions['mainy'] + 20);
    }
    if (!DEBUGGING) {
        imagepng($im);
    }
}
imagedestroy($im);
    imagesavealpha($final_image, true);
    $trans = imagecolorallocatealpha($final_image, 0, 0, 0, 127);
    imagefill($final_image, 0, 0, $trans);
    // Copy created avatar onto the plane
    if ($show_flipped) {
        $im = FlipImage($im);
    }
    imagecopy($final_image, $im, 0, 0, $w / 2 - $image_width / 2, $h / 2 - $image_height / 2, $image_width, $image_height);
    imagedestroy($im);
    $im = $final_image;
    // Change mainx/y
    $mainx = imagesx($im) / 2;
    $mainy = imagesy($im) / 2 + 18;
    // Render name
    if (isset($_GET['show_name'])) {
        RenderName($character_data['name'], $mainx, $mainy + 20);
    }
    if (!isset($_GET['NO_CACHING'])) {
        SaveCacheImage($internal_id, $image_mode, $im, $id);
    }
    if (DEBUGGING) {
        header('Content-type: text/plain');
    }
    imagepng($im);
}
imagedestroy($im);
// Function to phrase data into an array
function get_data($itemid)
{
    return GetItemWZInfo($itemid, CURRENT_LOCALE);
}