##// END OF EJS Templates
return base64-encoded image data from repr methods...
Min RK -
Show More
@@ -5,12 +5,7 b''
5 # Distributed under the terms of the Modified BSD License.
5 # Distributed under the terms of the Modified BSD License.
6
6
7
7
8 try:
8 from binascii import b2a_hex, b2a_base64
9 from base64 import encodebytes as base64_encode
10 except ImportError:
11 from base64 import encodestring as base64_encode
12
13 from binascii import b2a_hex
14 import json
9 import json
15 import mimetypes
10 import mimetypes
16 import os
11 import os
@@ -1135,6 +1130,7 b' class Image(DisplayObject):'
1135
1130
1136 def _data_and_metadata(self):
1131 def _data_and_metadata(self):
1137 """shortcut for returning metadata with shape information, if defined"""
1132 """shortcut for returning metadata with shape information, if defined"""
1133 b64_data = b2a_base64(self.data).decode('ascii')
1138 md = {}
1134 md = {}
1139 if self.metadata:
1135 if self.metadata:
1140 md.update(self.metadata)
1136 md.update(self.metadata)
@@ -1145,9 +1141,9 b' class Image(DisplayObject):'
1145 if self.unconfined:
1141 if self.unconfined:
1146 md['unconfined'] = self.unconfined
1142 md['unconfined'] = self.unconfined
1147 if md:
1143 if md:
1148 return self.data, md
1144 return b64_data, md
1149 else:
1145 else:
1150 return self.data
1146 return b64_data
1151
1147
1152 def _repr_png_(self):
1148 def _repr_png_(self):
1153 if self.embed and self.format == u'png':
1149 if self.embed and self.format == u'png':
@@ -1246,7 +1242,7 b' class Video(DisplayObject):'
1246 # unicode input is already b64-encoded
1242 # unicode input is already b64-encoded
1247 b64_video = video
1243 b64_video = video
1248 else:
1244 else:
1249 b64_video = base64_encode(video).decode('ascii').rstrip()
1245 b64_video = b2a_base64(video).decode('ascii').rstrip()
1250
1246
1251 output = """<video controls>
1247 output = """<video controls>
1252 <source src="data:{0};base64,{1}" type="{0}">
1248 <source src="data:{0};base64,{1}" type="{0}">
General Comments 0
You need to be logged in to leave comments. Login now