#NEWLINE# def make_base64( imgfile ) : #NEWLINE# #INDENT# with open ( imgfile ) as img : #NEWLINE# #INDENT# mtype = mimetypes . guess_type ( imgfile ) [ 0 ] #NEWLINE# data = binascii . b2a_base64 ( img . read ( ) ) . strip ( ) #NEWLINE# return 'data:{mtype};base64,{data}' . format ( mtype = mtype , data = data )