embedding image into jupyter notebook and exporting to HTML

后端 未结 3 1421
情话喂你
情话喂你 2020-12-31 15:49

I am running Python 3.7 on Windows using pycharm. I have a jupyter notebook and I would like to embed an image into the notebook. I know all the ways of doing standard embed

3条回答
  •  悲&欢浪女
    2020-12-31 16:36

    My complete solution is based on Milania and

    • encoding-an-image-file-with-base64
    • how-to-base64-encode-an-image-using-python
    • BytesIO.getvalue

    the code

        import base64, io, IPython
        from PIL import Image as PILImage
    
        image = PILImage.open(image_path)
    
        output = io.BytesIO()
        image.save(output, format='PNG')
        encoded_string = base64.b64encode(output.getvalue()).decode()
    
        html = ''.format(encoded_string)
        IPython.display.HTML(html)
    

提交回复
热议问题