import io


def to_byte_array(pil_image):
    """
    converts the PIL image into a bytes array.
    :param pil_image: PIL image to convert to
    :return: Bytes array representing the image.
    """
    with io.BytesIO() as bytes_io:
        pil_image.save(bytes_io, "PNG")
        bytes_io.seek(0)
        result = bytes_io.read()

    return result