<?php

if (isset($_GET['show'])) {

    require 'SkinViewer2D.class.php';
    header("Content-type: image/png");


    $skin_dir = $_SERVER['DOCUMENT_ROOT'] . '/cabinet/uploads/skins/';
    $cloak_dir = $_SERVER['DOCUMENT_ROOT'] . '/cabinet/uploads/cloaks/';

    $show = $_GET['show'];
    $name =  empty($_GET['file_name']) ? 'default' : $_GET['file_name'];
    $skin =  $skin_dir . $name . '.png';
    $cloak =  $cloak_dir . $name . '.png';

    if (!skinViewer2D::isValidSkin($skin)) {
        $skin = $skin_dir . 'default.png';
    }

    if ($show !== 'head') {
        $side = isset($_GET['side']) ? $_GET['side'] : false;

        $img = skinViewer2D::createPreview($skin, $cloak, $side);
    } else {
        $img = skinViewer2D::createHead($skin, 64);
    }

    imagepng($img);

}

?>
