PHP - .png和.gif一起发行

I run a website where users can customize their own avatar. They can upload items, like "hats" and "shirts", which can be uploaded as a .png or .gif. Then, the "avatar" is outputted. The code for that is below. However when I "wear" an hat that is a .png, it shows up on my avatar, but if I wear a hat that is a .gif, it doesn't appear. How do I make it so that the avatar outputs .png items and .gif items together?

//retrieve user info from request
//example: Avatar.php?ID=1 (page will load avatar for user with ID of 1)
$ID = $db->real_escape_string(strip_tags(stripslashes($_GET['ID'])));
$Username = $db->real_escape_string(strip_tags(stripslashes($_GET['Username'])));
if (!$Username) {
    $getUser = mysqli_query($db, "SELECT * FROM Users WHERE ID='".$ID."'");
}
else {
    $getUser = mysqli_query($db, "SELECT * FROM Users WHERE Username='".$Username."'");
}
$gU = mysqli_fetch_object($getUser);

//load clothing
$Body = $gU->Body;
if (empty($Body)) {
    $Body = "/Avatars/Avatar.png";
}

$Background = $gU->Background;
if (empty($Background)) {
    $Background = "thingTransparent.png";
}

$Eyes = $gU->Eyes;
if (empty($Eyes)) {
    $Eyes = "thingTransparent.png";
}

$Mouth = $gU->Mouth;
if (empty($Mouth)) {
    $Mouth = "thingTransparent.png";
}

$Hair = $gU->Hair;
if (empty($Hair)) {
    $Hair = "thingTransparent.png";
}

$Bottom = $gU->Bottom;
if (empty($Bottom)) {
    $Bottom = "thingTransparent.png";
}

$Top = $gU->Top;
if (empty($Top)) {
    $Top = "thingTransparent.png";
}

$TShirt = $gU->TShirt;
if (empty($TShirt)) {
    $TShirt = "thingTransparent.png";
}

$Hat3 = $gU->Hat3;
if (empty($Hat3)) {
    $Hat3 = "thingTransparent.png";
}

$Hat2 = $gU->Hat2;
if (empty($Hat2)) {
    $Hat2 = "thingTransparent.png";
}

$Hat = $gU->Hat;
if (empty($Hat)) {
    $Hat = "thingTransparent.png";
}

$Shoes = $gU->Shoes;
if (empty($Shoes)) {
    $Shoes = "thingTransparent.png";
}

$Accessory = $gU->Accessory;
if (empty($Accessory)) {
    $Accessory = "thingTransparent.png";
}


//render the avatar image
class StackImage
{
    private $image;
    private $width;
    private $height;

    public function __construct($Path)
    {
        if(!isset($Path) || !file_exists($Path))
        return;
        $this->image = imagecreatefrompng($Path);
        imagesavealpha($this->image, true);
        imagealphablending($this->image, true);
        $this->width = imagesx($this->image);
        $this->height = imagesy($this->image);
    }

    public function AddLayer($Path)
    {
        if(!isset($Path) || !file_exists($Path))
            return;
        $new = imagecreatefrompng($Path);
        imagesavealpha($new, true);
        imagealphablending($new, true);
        imagecopy($this->image, $new, 0, 0, 0, 0, imagesx($new), imagesy($new));
    }

    public function Output($type = "image/png")
    {
        header("Content-Type: {$type}");
        imagepng($this->image);
        imagedestroy($this->image);
    }

    public function GetWidth()
    {
        return $this->width;
    }

    public function GetHeight()
    {
        return $this->height;
    }
}

//add layer to image for the items that the user is wearing
//must be in specific order so you don't have unnecessary items overlapping each other incorrectly
//don't touch the bottom code
$Image = new StackImage("Store/Dir/thingTransparent.png");
$Image->AddLayer("Store/Dir/".$Background."");
$Image->AddLayer("Store/Dir/".$Body."");
$Image->AddLayer("Store/Dir/".$Eyes."");
$Image->AddLayer("Store/Dir/".$Mouth."");
$Image->AddLayer("Store/Dir/".$Bottom."");
$Image->AddLayer("Store/Dir/".$Top."");
$Image->AddLayer("Store/Dir/".$TShirt."");
$Image->AddLayer("Store/Dir/".$Hair."");
$Image->AddLayer("Store/Dir/".$Hat."");
$Image->AddLayer("Store/Dir/".$Shoes."");
$Image->AddLayer("Store/Dir/".$Accessory."");

//if the user is online, show online symbol
if (time() < $gU->expireTime) {
    $Image->AddLayer("Images/Online.png");
}
//or else if the user is offline, show offline symbol
else {
    $Image->AddLayer("Images/Offline.png");
}

//if the user is premium, show a little premium icon to the bottom left of their avatar
if ($gU->Premium == 1) {
    $Image->AddLayer("Images/Premium.png");
}

//load up the rendered image
$Image->Output();

In AddLayer() you might need to change this line

$new = imagecreatefrompng($Path);

to check whether the source is GIF or PNG and then use the appropriate "imagecreatefrom*() method.