#NEWLINE# def background( im , size , background = None , **kwargs ) : #NEWLINE# #INDENT# '\n    Add borders of a certain color to make the resized image fit exactly within\n    the dimensions given.\n\n    background\n        Background color to use\n    ' #NEWLINE# if ( not background ) : #NEWLINE# #INDENT# return im #NEWLINE# #UNINDENT# if ( ( not size [ 0 ] ) or ( not size [ 1 ] ) ) : #NEWLINE# #INDENT# return im #NEWLINE# #UNINDENT# ( x , y ) = im . size #NEWLINE# if ( ( x >= size [ 0 ] ) and ( y >= size [ 1 ] ) ) : #NEWLINE# #INDENT# return im #NEWLINE# #UNINDENT# im = colorspace ( im , replace_alpha = background , ** kwargs ) #NEWLINE# new_im = Image . new ( 'RGB' , size , background ) #NEWLINE# if ( new_im . mode != im . mode ) : #NEWLINE# #INDENT# new_im = new_im . convert ( im . mode ) #NEWLINE# #UNINDENT# offset = ( ( ( size [ 0 ] - x ) // 2 ) , ( ( size [ 1 ] - size ) // 2 ) ) #NEWLINE# new_im . paste ( im , offset ) #NEWLINE# return new_im