def render_player(self, player, armor=True):
        """Return an Image of a fully rendered player from a save."""
        name = player.get_race()
        gender = player.get_gender()
        species = self.get_species(name.lower())

        if species is None:
            return Image.open(BytesIO(self.assets.items().missing_icon()))

        asset_loc = species[0][1]

        # crop the spritesheets and replace colours
        def grab_sprite(sheet_path, rect, directives):
            sheet = self.assets.read(sheet_path, asset_loc, True)
            img = Image.open(BytesIO(sheet)).convert("RGBA").crop(rect)
            if directives != "":
                img = replace_colors(img, unpack_color_directives(directives))
            return img

        default_rect = (43, 0, 86, 43)
        # TODO: should use the .bbox to figure this out
        personality = player.get_personality()
        personality_offset = int(re.search("\d$", personality).group(0)) * 43
        body_rect = (personality_offset, 0, personality_offset+43, 43)

        body_img = grab_sprite("/humanoid/%s/%sbody.png" % (name, gender),
                               body_rect,
                               player.get_body_directives())
        frontarm_img = grab_sprite("/humanoid/%s/frontarm.png" % name,
                                   body_rect,
                                   player.get_body_directives())
        backarm_img = grab_sprite("/humanoid/%s/backarm.png" % name,
                                  body_rect,
                                  player.get_body_directives())
        head_img = grab_sprite("/humanoid/%s/%shead.png" % (name, gender),
                               default_rect,
                               player.get_body_directives())

        hair = player.get_hair()
        hair_img = None
        if hair[0] != "":
            hair_img = self.get_hair_image(
                name, hair[0],
                hair[1], gender,
                player.get_hair_directives()
            )

        facial_hair = player.get_facial_hair()
        facial_hair_img = None
        if facial_hair[0] != "":
            facial_hair_img = self.get_hair_image(
                name, facial_hair[0],
                facial_hair[1], gender,
                player.get_facial_hair_directives()
            )

        facial_mask = player.get_facial_mask()
        facial_mask_img = None
        if facial_mask[0] != "":
            facial_mask_img = self.get_hair_image(
                name, facial_mask[0],
                facial_mask[1], gender,
                player.get_facial_mask_directives()
            )

        head_slot = player.get_visible("head")
        chest_slot = player.get_visible("chest")
        legs_slot = player.get_visible("legs")
        back_slot = player.get_visible("back")
        do_head = armor and head_slot is not None

        # new blank canvas!
        base_size = 43
        base = Image.new("RGBA", (base_size, base_size))

        # the order of these is important!

        # back arm
        base.paste(backarm_img)
        if armor and chest_slot is not None:
            base = self.render_chest(player, base, chest_slot, "bsleeve")

        # backpack
        if armor and back_slot is not None:
            base = self.render_part(player, base, "back", back_slot)

        # then the head
        base.paste(head_img, mask=head_img)

        # TODO: support mask on head items
        if hair_img is not None:
            try:
                base.paste(hair_img, mask=hair_img)
            except __HOLE__:
                logging.exception("Bad hair image: %s, %s", hair[0], hair[1])

        # body
        base.paste(body_img, mask=body_img)
        if armor and legs_slot is not None:
            base = self.render_part(player, base, "legs", legs_slot)
        if armor and chest_slot is not None:
            base = self.render_chest(player, base, chest_slot, "body")

        # front arm
        base.paste(frontarm_img, mask=frontarm_img)
        if armor and chest_slot is not None:
            base = self.render_chest(player, base, chest_slot, "fsleeve")

        # facial mask if set
        if facial_mask_img is not None:
            try:
                base.paste(facial_mask_img, mask=facial_mask_img)
            except ValueError:
                logging.exception("Bad facial mask image: %s, %s",
                                  facial_mask[0], facial_mask[1])

        # facial hair if set
        if facial_hair_img is not None:
            try:
                base.paste(facial_hair_img, mask=facial_hair_img)
            except ValueError:
                logging.exception("Bad facial hair image: %s, %s",
                                  facial_hair[0], facial_hair[1])

        if do_head:
            base = self.render_part(player, base, "head", head_slot)

        return base.resize((base_size*3, base_size*3))
dataset/ETHPy150Open wizzomafizzo/starcheat/starcheat/assets/species.py/Species.render_player