#NEWLINE# def _image_resize( self , filepath ) : #NEWLINE# #INDENT# "Resizes Image if it's over the maximum dimension" #NEWLINE# filepath = filepath . replace ( settings . MEDIA_URL , '' ) #NEWLINE# filepath = ( settings . MEDIA_ROOT + filepath ) #NEWLINE# try : #NEWLINE# #INDENT# img = Image . open ( filepath ) #NEWLINE# expected_size = getattr ( settings , 'HARDTREE_IMAGE_MAX_SIZE' , [ 400 , 300 ] ) #NEWLINE# if ( ( img . size [ 0 ] > expected_size [ 0 ] ) or ( img . size [ 1 ] > expected_size [ 1 ] ) ) : #NEWLINE# #INDENT# filter_name = getattr ( settings , 'HARDTREE_IMAGE_RESIZE_FILTER' , 'ANTIALIAS' ) #NEWLINE# filter = getattr ( Image , filter_name , Image . ANTIALIAS ) #NEWLINE# aspect = ( img . size [ 0 ] / float ( img . size [ 1 ] ) ) #NEWLINE# newsize = list ( expected_size ) #NEWLINE# if ( img . size [ 0 ] > expected_size [ 0 ] ) : #NEWLINE# #INDENT# newsize [ 0 ] = expected_size [ 0 ] #NEWLINE# newsize [ 1 ] = round ( ( newsize [ 0 ] / aspect ) ) #NEWLINE# #UNINDENT# if ( newsize [ 1 ] > expected_size [ 1 ] ) : #NEWLINE# #INDENT# newsize [ 1 ] = expected_size [ 1 ] #NEWLINE# newsize [ 0 ] = round ( ( newsize [ 1 ] * aspect ) ) #NEWLINE# #UNINDENT# img = img . resize ( newsize , filter ) #NEWLINE# img . save ( filepath ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception : #NEWLINE# #INDENT# pass