def embed_image_html(image):
 if (image is None):
  return None
 elif isinstance(image, PIL.Image.Image):
  pass
 elif isinstance(image, np.ndarray):
  image = PIL.Image.fromarray(image)
 else:
  raise ValueError('image must be a PIL.Image or a np.ndarray')
 fmt = image.format
 if (not fmt):
  fmt = 'png'
 else:
  fmt = fmt.lower()
 string_buf = StringIO()
 image.save(string_buf, format=fmt)
 data = string_buf.getvalue().encode('base64').replace('\n', '')
 return ('data:image/%s;base64,%s' % (fmt, data))

def embed_image_html ( image ) : if ( image is None ) : return None elif isinstance ( image , PIL . Image . Image ) : pass elif isinstance ( image , np . ndarray ) : image = PIL . Image . fromarray ( image ) else : raise ValueError ( 'image must be a PIL.Image or a np.ndarray' ) fmt = image . format if ( not fmt ) : fmt = 'png' else : fmt = fmt . lower ( ) string_buf = StringIO ( ) image . save ( string_buf , format = fmt ) data = string_buf . getvalue ( ) . encode ( 'base64' ) . replace ( '\n' , '' ) return ( 'data:image/%s;base64,%s' % ( fmt , data ) )
returns an image embedded in html base64 format arguments: image -- a pil .