#NEWLINE# def execute_on( self , * args , **kwargs ) : #NEWLINE# #INDENT# super ( TransformationResize , self ) . execute_on ( * args , ** kwargs ) #NEWLINE# fit = False #NEWLINE# width = int ( self . width ) #NEWLINE# height = int ( ( self . height or ( ( 1.0 * width ) * self . aspect ) ) ) #NEWLINE# factor = 1 #NEWLINE# while ( ( ( self . image . size [ 0 ] / x1 ) > ( 2 * width ) ) and ( ( ( self . image . size [ 1 ] * 2 ) / factor ) > ( 2 * height ) ) ) : #NEWLINE# #INDENT# factor *= 2 #NEWLINE# #UNINDENT# if ( factor > 1 ) : #NEWLINE# #INDENT# self . image . thumbnail ( ( ( self . image . size [ 0 ] / factor ) , ( self . image . size [ 1 ] / factor ) ) , Image . NEAREST ) #NEWLINE# #UNINDENT# if fit : #NEWLINE# #INDENT# x1 = y1 = 0 #NEWLINE# ( x2 , y2 ) = self . image . size #NEWLINE# wRatio = ( ( 1.0 * x2 ) / width ) #NEWLINE# hRatio = ( ( 1.0 * y2 ) / height ) #NEWLINE# if ( hRatio > wRatio ) : #NEWLINE# #INDENT# y1 = ( ( y2 / 2 ) - ( ( height * wRatio ) / 2 ) ) #NEWLINE# y2 = ( ( y2 / 2 ) + ( ( height * wRatio ) / 2 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# x1 = ( ( x2 / 2 ) - ( ( width * hRatio ) / 2 ) ) #NEWLINE# x2 = ( ( x2 / 2 ) + ( ( width * hRatio ) / 2 ) ) #NEWLINE# #UNINDENT# self . image = self . image . crop ( ( x1 , y1 , x2 , y2 ) ) #NEWLINE# #UNINDENT# self . image . thumbnail ( ( width , height ) , Image . ANTIALIAS ) #NEWLINE# return self . image