#NEWLINE# def save( self , data , file_id = None , metadata = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , THUMB_SIZE = ( ) ) : #NEWLINE# #INDENT# if ( file_id is None ) : #NEWLINE# #INDENT# file_id = unicode ( uuid . uuid4 ( ) ) #NEWLINE# #UNINDENT# with open ( self . _get_filename ( file_id ) , 'w' ) as f : #NEWLINE# #INDENT# f . write ( data ) #NEWLINE# #UNINDENT# with open ( self . _get_metadata_filename ( file_id ) , 'w' ) as f : #NEWLINE# #INDENT# f . write ( json . dumps ( data ) ) #NEWLINE# #UNINDENT# img = None #NEWLINE# try : #NEWLINE# #INDENT# img = Image . open ( self . _get_filename ( file_id ) ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# log . info ( 'Not an image file, skipping medium & thumbnail generation' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# kw = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( 'transparency' in img . info ) : #NEWLINE# #INDENT# kw [ 'transparency' ] = img . info [ 'transparency' ] #NEWLINE# #UNINDENT# ( orig_width , orig_height ) = img . size #NEWLINE# medium_size = ( self . MEDIUM_WIDTH , int ( ( ( float ( self . MEDIUM_WIDTH ) * orig_height ) / orig_width ) ) ) #NEWLINE# medium = img . copy ( ) #NEWLINE# medium . thumbnail ( medium_size , Image . ANTIALIAS ) #NEWLINE# medium . save ( self . _get_filename ( file_id , 'medium' ) , img . format , quality = 75 , ** kw ) #NEWLINE# thumb = ImageOps . fit ( img , ( THUMB_SIZE if THUMB_SIZE else self . THUMB_SIZE ) , Image . ANTIALIAS ) #NEWLINE# thumb . save ( self . _get_filename ( file_id , 'thumb' ) , img . format , quality = 75 , ** kw ) #NEWLINE# #UNINDENT# return file_id