mirrored 17 minutes ago
0
HiroidAdd multiple new modules and tools to enhance the functionality and extensibility of the Maestro project (#333) * Added a **pyproject.toml** file to define project metadata and dependencies. * Added **run\_maestro.py** and **osworld\_run\_maestro.py** to provide the main execution logic. * Introduced multiple new modules, including **Evaluator**, **Controller**, **Manager**, and **Sub-Worker**, supporting task planning, state management, and data analysis. * Added a **tools module** containing utility functions and tool configurations to improve code reusability. * Updated the **README** and documentation with usage examples and module descriptions. These changes lay the foundation for expanding the Maestro project’s functionality and improving the user experience. Co-authored-by: Hiroid <guoliangxuan@deepmatrix.com>3a4b673
from PIL import Image


def pad_to_square(image: Image.Image,
                  fill_color=(0, 0, 0),
                  padding: int = 0) -> Image.Image:
    """
    First make it a square, then expand the padding pixels around it.
    """
    width, height = image.size
    if width == height:
        square_img = image.copy()
    else:
        new_size = max(width, height)
        square_img = Image.new(image.mode, (new_size, new_size), fill_color)
        left = (new_size - width) // 2
        top = (new_size - height) // 2
        square_img.paste(image, (left, top))

    if padding > 0:
        final_size = square_img.size[0] + 2 * padding
        padded_img = Image.new(square_img.mode, (final_size, final_size),
                               fill_color)
        padded_img.paste(square_img, (padding, padding))
        return padded_img
    else:
        return square_img