def resize(img, size, interpolation=Image.BILINEAR):
if not _is_pil_image(img):<EOL><INDENT>raise TypeError('<STR_LIT>'.format(type(img)))<EOL><DEDENT>if not (isinstance(size, int) or (isinstance(size, Iterable) and len(size) == <NUM_LIT:2>)):<EOL><INDENT>raise TypeError('<STR_LIT>'.format(size))<EOL><DEDENT>if isinstance(size, int):<EOL><INDENT>w, h = img.size<EOL>if (w <= h and w == size) or (h <= w and h == size):<EOL><INDENT>return img<EOL><DEDENT>if w < h:<EOL><INDENT>ow = size<EOL>oh = int(size * h / w)<EOL>return img.resize((ow, oh), interpolation)<EOL><DEDENT>else:<EOL><INDENT>oh = size<EOL>ow = int(size * w / h)<EOL>return img.resize((ow, oh), interpolation)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return img.resize(size[::-<NUM_LIT:1>], interpolation)<EOL><DEDENT>
r"""Resize the input PIL Image to the given size.

    Args:
        img (PIL Image): Image to be resized.
        size (sequence or int): Desired output size. If size is a sequence like
            (h, w), the output size will be matched to this. If size is an int,
            the smaller edge of the image will be matched to this number maintaing
            the aspect ratio. i.e, if height > width, then image will be rescaled to
            :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)`
        interpolation (int, optional): Desired interpolation. Default is
            ``PIL.Image.BILINEAR``

    Returns:
        PIL Image: Resized image.