3 Ways to Add Images to Your Jupyter Notebook

And learn a little bit about Base64 encoding

Python
Data Science
Visualization
Jupyter
Author
Published

March 4, 2021

Note

👉 This article is also published on Better Programming blog.

Introduction

The Jupyter Notebook (formerly IPython Notebooks) is a popular web-based interactive environment that was first started from the IPython project and is currently maintained by the nonprofit organization Project Jupyter. It’s a convenient tool to create and share documents that contain codes, equations, texts, and visualizations. A Jupyter Notebook can be easily converted to HTML, LaTeX, PDF, Markdown, Python, and other open standard formats1.

In this post, I will present three ways to add images to your notebook. The first two approaches are pretty standard that rely on external resources to illustrate the images, and those are to use the image URL or to load an image from a local file. However, both of these methods rely on external resources. To contain all images used in the notebook within itself without relying on any external source, we can use the Base64 encoding algorithm to encode our images and use those encoded data to illustrate them. So, we will briefly talk about the Base64 algorithm too.

Here, I will be using the Image class from IPython’s display module to show all images.

Approach 1: Add an image from a local file

We can add images from your local drive by providing the path to the file.

from IPython import display
display.Image("./image.png")

There are two downsides to this approach:

  1. The local or absolute path provided may not work well on another system.

  2. You have to make sure to include all images used in a notebook with anyone you want to share. You may end up compressing all files to a single zip file for convenience when sharing your notebook.

Approach 2: Add an image from a URL

You can also add an image to your notebook using the URL link to the image, as shown below.

from IPython import display
display.Image("URL of the image")

In this case, the image provider may remove the image or change the image properties without knowing it. So, let’s say you have an old notebook that has a broken image link. It might be difficult to retrieve the original image. Even if you are taken the image from your website, you should be careful not to change the image link or properties!

Approach 3: Embed an image by Base64 Encode-Decode

The first two approaches rely on external resources. In Section 2, we used the path to a file that is saved locally. Any change in the filename or path may impact the image in the notebook. In Section 3, we rely on a URL, and any change in the original link will impact the image in the notebook. Unlike the previous methods, Approach 3 embeds the image as a text using the Base64 encoding algorithm. This way, we will not be relying on any external resources for the embedded image. Hence, we can have all images embedded in the same notebook file.

Base64 is a binary-to-text encoding algorithm to convert data (including but not limited to images) as plain text. It is one of the most popular binary-to-text encoding schemes (if not the most one). It’s widely used in text documents such as HTML, JavaScript, CSS, or XML scripts2. However, technically speaking, you can even encode/decode audio or video files too!!

First, you need to encode your image. For this, you can use the online tool Base64-Image. After you upload your image, you can then click on the copy image, as shown below.

Screenshot

Screenshot of the uploaded image at base64-image

Now you can paste the encoded image code into your notebook, but first, you should remove data:image/png;base64, at the beginning. Don’t forget to also remove the comma after base64!

Now that we have the encoded image code, we can use the Python standard base64 library to decode the base64 data, as shown below.

from IPython import display
from base64 import b64decode
base64_data = "iVBORw0KGgoAAAANSUhEUgAAA8oAAACVCAYAAACAXwOLAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAC9TSURBVHhe7d0PeFT1ne/xL4JBCgFK4h+wQOpi/HNJ710D1w1t+VOfJt6t9FqoexuoCvtU2OfR6C500cb2iblt458lPNsN3EfQ5wJWSPdaUq+xrYlrQXol2wfivdthoQaqATTxT5ICASER9f7+nZkzk5nJJMwkk+T90kPOnDNz5syZ8+/z+/3OmVEffnjm03HjxgsAAAAAACPVuXNn5e233zT9lxCSAQAAAAAjnc7GEyd+1vRfYv4FAAAAAGCEy8ycbP4SlAEAAAAAULwW1wRlAAAAAACUUaNGmb8EZQAAAAAAfAjKAAAAAAD4EJQBAAAAAPAhKAMAAAAA4ENQBgAAAADAh6AMAAAAAIAPQRkAAAAAAB+CMgAAAAAAPgRlAAAAAAB8CMoAAAAAAPgQlAEAAAAA8CEoAwAAAADgQ1AGAAAAAMCHoAwAAAAAgA9BGQAAAAAAH4IyAAAAAAA+BGUAAAAAAHwIygAAAAAA+BCUAQAAAADwISgDAAAAAOBDUAYAAAAAwIegHE1brZTMmSNzTFcpATe4K7BNViycI/OKSqWuxQ0EAAAAAAwrSQ/KbbUlLmBG7yq91DnktMmeLRvl4BmR7vZ62Vj/hhsOAAAAABhOqFFOWLZcVzDT9WdIfs401w8AAAAAGE5SG5QnzJTc3NywbqobNRTlLNslu3++VXa8sFseWZjphgIAAAAAhpPUBuXFj8jOnTvDumV5btwQlZmTJ9dNG+seAQAAAABS5tw5Od1x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oIyAAAAgJQYqqGZcAyCMgAAAIABka7BmWCMSARlAAAAAINqoAI0gRiJIigDAAAAAOCjg/Ilrh8AAAAAACgEZQAAAAAAfAjKAAAAAAD4EJQBAAAAAPAhKAMAAAAAoHz88QXzl6AMAAAAAIDS1XXe/CUoAwAAAACgnDzZbv5e8uGHZ0wPAAAAAAAj1dmzp00nIvL/ATr9BRu5TEnOAAAAAElFTkSuQmCC"

display.Image(b64decode(base64_data))

An image decoded from Base64

As you may have noticed by now, the main advantage of using Base64 to add all images to your Notebook is the fact that do yo no longer need to worry about any external resources for your images as they are all self-contained in your Notebook. The other point to be aware of is that including the images in your notebook will increase your notebook’s file size depending on the image resolution.

Conclusion

In this post, we went over three ways to add an image to a Jupyter Notebook, and those are through 1) a URL, 2) a local file, or 3) by Base64 encoding the image data. I also provided a resource link that you can use to Base64 encode your image. The main benefit of using the Base64 encoding scheme is to reduce (or even) remove any external images in your notebook.

Note

📓 You can find the notebook for this post on GitHub.

Footnotes

  1. Wikipedia, Project Jupyter (Accessed on November 16, 2020)↩︎

  2. Wikipedia, Base64 (Accessed on November 16, 2020)↩︎

Citation

BibTeX citation:
@online{alizadeh2020,
  author = {Alizadeh, Esmaeil},
  title = {3 {Ways} to {Add} {Images} to {Your} {Jupyter} {Notebook}},
  date = {2020-11-06},
  url = {https://ealizadeh.com/blog/3-ways-to-add-images-to-your-jupyter-notebook/},
  langid = {en}
}
For attribution, please cite this work as:
E. Alizadeh, “3 Ways to Add Images to Your Jupyter Notebook,” Nov. 06, 2020. https://ealizadeh.com/blog/3-ways-to-add-images-to-your-jupyter-notebook/

No Spam. Unsubscribe anytime.