Commit 2f1e177e authored by Romain Casati's avatar Romain Casati
Browse files

Towards PIL support.

parent d2651022
......@@ -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}`]();
......
......@@ -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()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment