Exemplo n.º 1
0
def rescale(img: Image,
            scale: Union[float, Tuple[float, float]],
            kernel: str = Kernel.LINEAR) -> Image:
    if isinstance(scale, float):
        return img.resize(scale, kernel=kernel)
    else:
        scale, vscale = scale
        return img.resize(scale, vscale=vscale, kernel=kernel)
Exemplo n.º 2
0
def pyvips_resize_by_size(img: Image,
                          size: Tuple[int, int],
                          kernel: str = Kernel.LINEAR) -> Image:
    """
    size -> height, width
    """
    # w, h = size
    h, w = size
    scale = w / img.width
    vscale = h / img.height
    return img.resize(scale, vscale=vscale, kernel=kernel)
Exemplo n.º 3
0
def resize(img: Image,
           size: Union[int, Tuple[int, int]],
           kernel: str = Kernel.LINEAR):
    """
    (h, w)
    """

    if isinstance(size, int):
        w, h = img.width, img.height

        if (w <= h and w == size) or (h <= w and h == size):
            return img

        # resize shorter edge
        if w < h:
            scale = size / w
        else:
            scale = size / h

        return img.resize(scale, kernel=kernel)

    else:
        return pyvips_resize_by_size(img, size, kernel=kernel)