jupyter-notebook

How to export images in Jupyter notebook attachment:media to disk files?


I have a Jupyter notebook with some images in the attachment that look like this:

<img src="attachment:media/image20.png" style="width:2.83in;height:2.85in" /> 

I wanted to use this image elsewhere, but I couldn't find the image file image20.png or the media folder anywhere on the hard drive. I guess the image file is somewhere inside the .ipynb itself.

My question is:

How to export the image file referenced by attachment:media/... to an actual .png file on the disk?

Note: I searched around on SO, and only found answers to export the output of a cell. e.g.

Jupyter Notebook: automatically saves all images

(, ... or saving the output of a maplotlib plot function.)

But the images above are not from the output of any code cell or code. I can see the image in the notebook, but not the actual .png file in the file system.


Solution

  • You can view as text and extract the value from a JSON dictionary under keyword "image/png". This has been automated for use from the command line in the Junix repo https://github.com/damienmarlier51/Junix as described by the author at

    https://medium.com/analytics-vidhya/export-images-from-jupyter-notebook-with-a-single-command-422db2b66e92