import math


def make_tiles(image, tile_width, tile_height):
    """
    slice PIL image to tiles

    :param image: PIL image
    :param tile_width: target tile width
    :param tile_height: target tile height
    :return: 2d array of PIL images
    """
    width_segments = math.floor(image.width / tile_width)
    height_segments = math.floor(image.height / tile_height)

    matrix = [[0 for i in range(width_segments)] for i in range(height_segments)]

    for h in range(height_segments):
        y_from = h * tile_height
        y_to = y_from + tile_height

        for w in range(width_segments):
            x_from = w * tile_width
            x_to = x_from + tile_width

            frame = image.crop((x_from, y_from, x_to, y_to))
            matrix[h][w] = frame
    return matrix