Convert this code to typescript 

function resizeimage($imagefile, $newwidth = 1280, $newheight = 960){

    $width = imagesx($imagefile);
    $height = imagesy($imagefile);

    if ($width > $newwidth || $height > $newheight){
    if($width > $height){
        $newheight = ($height/$width)*$newwidth;
    }else{
        $newwidth = ($width/$height)*$newheight;
    }
    $newimage = imagecreatetruecolor($newwidth, $newheight);
    imagecopyresampled($newimage, $imagefile, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    return $newimage;
    }else{
        return $imagefile;
    }
}