File tree 2 files changed +12
-3
lines changed 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 9
9
import markdown
10
10
import logging
11
11
import subprocess
12
+ import base64
13
+ import hashlib
12
14
13
15
14
16
logging .basicConfig (level = logging .INFO , format = '%(asctime)s - %(levelname)s - %(message)s' )
@@ -46,7 +48,14 @@ def image_from_cell(cell):
46
48
try :
47
49
for c in cell ['outputs' ]:
48
50
if 'data' in c and 'image/png' in c ['data' ]:
49
- return c ['data' ]['image/png' ].replace ("\n " , "" ).strip ()
51
+ base64_img = c ['data' ]['image/png' ].replace ("\n " , "" ).strip ()
52
+ filename = hashlib .md5 ()
53
+ filename .update (base64_img .encode ('ascii' ))
54
+ web_path = "/img/plots/{}.png" .format (filename .hexdigest ())
55
+ full_path = "web" + web_path
56
+ with open (full_path , "wb" ) as fh :
57
+ fh .write (base64 .b64decode (base64_img ))
58
+ return web_path
50
59
except KeyError as e :
51
60
logging .error ("Can't find image in cell: %s" , cell ['source' ])
52
61
raise e
Original file line number Diff line number Diff line change @@ -131,8 +131,8 @@ <h3 class="card-title mb-1">{{ name }}</h3>
131
131
< div class ="container-fluid ">
132
132
< div class ="row ">
133
133
< div class ="col-lg-6 col-xs-12 p-lg-0 ">
134
- < a href ="data:image/png;base64, {{ plot['image'] }} " data-toggle ="lightbox " data-title ="{{ name }} - {{ plot['package'] }} ">
135
- < img src ="data:image/png;base64, {{ plot['image'] }} " class ="img-fluid ">
134
+ < a href ="{{ plot['image'] }} " data-toggle ="lightbox " data-title ="{{ name }} - {{ plot['package'] }} ">
135
+ < img src ="{{ plot['image'] }} " class ="img-fluid ">
136
136
</ a >
137
137
</ div >
138
138
< div class ="col-lg-6 col-xs-12 p-0 right-col d-inline-flex flex-column ">
You can’t perform that action at this time.
0 commit comments