Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Basthon
Basthon Kernel
Commits
2f1e177e
Commit
2f1e177e
authored
Jan 02, 2021
by
Romain Casati
Browse files
Towards PIL support.
parent
d2651022
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/basthon.js
View file @
2f1e177e
...
...
@@ -373,7 +373,7 @@
*/
that
.
hackPackagesCallback
=
function
(
toLoad
)
{
const
hacked
=
[
"
matplotlib
"
,
"
turtle
"
,
"
sympy
"
,
"
folium
"
,
"
pandas
"
];
"
folium
"
,
"
pandas
"
,
"
PIL
"
];
for
(
const
p
of
toLoad
)
if
(
hacked
.
includes
(
p
)
)
pyodide
.
globals
.
Basthon
[
`hack_
${
p
}
`
]();
...
...
src/basthon.py.js
View file @
2f1e177e
...
...
@@ -391,6 +391,30 @@ class BasthonNamespace(object):
DataFrame.display = display
def hack_PIL(self):
from PIL import Image, ImageShow
import io
from base64 import b64encode
# preserve access to self
this = self
# pluging for Notebook
def _repr_png_(self):
byio = io.BytesIO()
self.save(byio, format='PNG')
return b64encode(byio.getvalue()).decode()
Image.Image._repr_png_ = _repr_png_
# pluging image.show()
class basthonviewer(ImageShow.Viewer):
def show_image(self, image, **options):
this.basthon_internal.display(image)
ImageShow._viewers = []
ImageShow.register(basthonviewer)
Basthon = BasthonNamespace()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment