resizeimage/resizeimage.py
def resize_contain(image, size, resample=Image.LANCZOS, bg_color=(255, 255, 255, 0)):
    """
    Resize image according to size.
    image:      a Pillow image instance
    size:       a list of two integers [width, height]
    """
    img_format = image.format
    img = image.copy()
    img.thumbnail((size[0], size[1]), resample)
    background = Image.new('RGBA', (size[0], size[1]), bg_color)
    img_position = (
        int(math.ceil((size[0] - img.size[0]) / 2)),
        int(math.ceil((size[1] - img.size[1]) / 2))
    )
    background.paste(img, img_position)
    background.format = img_format
    return background.convert('RGB')
def resize_contain(image, size, resample=Image.LANCZOS, bg_color=(255, 255, 255, 0)):
    """
    Resize image according to size.
    image:      a Pillow image instance
    size:       a list of two integers [width, height]
    """
    img_format = image.format
    img = image.copy()
    img.thumbnail((size[0], size[1]), resample)
    background = Image.new('RGBA', (size[0], size[1]), bg_color)
    img_position = (
        int(math.ceil((size[0] - img.size[0]) / 2)),
        int(math.ceil((size[1] - img.size[1]) / 2))
    )
    background.paste(img, img_position)
    background.format = img_format
    return background.convert('RGB')
def resize_contain ( image , size , resample = Image . LANCZOS , bg_color = ( 255 , 255 , 255 , 0 ) ) : img_format = image . format img = image . copy ( ) img . thumbnail ( ( size [ 0 ] , size [ 1 ] ) , resample ) background = Image . new ( 'RGBA' , ( size [ 0 ] , size [ 1 ] ) , bg_color ) img_position = ( int ( math . ceil ( ( size [ 0 ] - img . size [ 0 ] ) / 2 ) ) , int ( math . ceil ( ( size [ 1 ] - img . size [ 1 ] ) / 2 ) ) ) background . paste ( img , img_position ) background . format = img_format return background . convert ( 'RGB' )
Resize image according to size.
    image:      a Pillow image instance
    size:       a list of two integers [width, height]
Resize image according to size . image : a Pillow image instance size : a list of two integers [ width height ]