Table of Contents
Google Colab is awesome. It runs in your browser. It feels like magic. And yes, you can work with images inside it very easily. If you have ever wondered how to upload, display, or insert images into your notebook, this guide will make it simple and fun.
TLDR: You can insert images into Google Colab in three main ways: upload from your computer, use images from Google Drive, or display images from a URL. The most common method uses Python libraries like IPython.display, matplotlib, or PIL. Uploading is easy with a built-in file upload tool. Once the image is in your environment, you can display it inline in just a few lines of code.
Let’s break it down step by step.
This is the simplest way to get started. You have an image on your laptop. You want it inside Colab. Done in seconds.
Colab has a built-in upload tool. You can use it with this code:
from google.colab import files
uploaded = files.upload() When you run this cell, a file picker pops up. Choose your image. That’s it. Your file is now inside the session.
Important: Colab sessions are temporary. If you restart the runtime, your uploaded files disappear. So keep that in mind.
After uploading, you can display the image.
This is one of the easiest display methods:
from IPython.display import Image
from IPython.display import display
display(Image('your_image_name.jpg')) Replace the file name with yours. The image will appear directly below the code cell. Nice and clean.
Image not found in postmetaIf you are doing data science or machine learning, you will love this method. It gives more control. You can resize. Add titles. Hide axes. Customize everything.
First, install and import the needed libraries. Usually, they are already available in Colab:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg Now load and show the image:
img = mpimg.imread('your_image_name.jpg')
plt.imshow(img)
plt.axis('off')
plt.show() Let’s break that down:
Simple. But powerful.
You can also add a title:
plt.title('My Awesome Image') This is great when presenting results.
PIL is another easy option. In modern Python, you usually use Pillow, which is the updated version of PIL.
Here’s how:
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('your_image_name.jpg')
plt.imshow(img)
plt.axis('off') Why use PIL?
For example, resizing:
img_resized = img.resize((200, 200))
plt.imshow(img_resized)
plt.axis('off') Very handy for machine learning preprocessing.
What if your image is not on your computer, but in Google Drive?
No problem.
First, mount your Drive:
from google.colab import drive
drive.mount('/content/drive') You will see a link. Click it. Authorize. Paste the code back. Done.
Your files are now accessible like normal folders.
Example path:
/content/drive/MyDrive/images/photo.jpg Now display it using any method from above. For example:
display(Image('/content/drive/MyDrive/images/photo.jpg')) This method is great for:
You do not even need to upload files. You can display images directly from the internet.
Here’s how:
import requests
from PIL import Image
from io import BytesIO
import matplotlib.pyplot as plt
url = "https://example.com/image.jpg"
response = requests.get(url)
img = Image.open(BytesIO(response.content))
plt.imshow(img)
plt.axis('off') This is perfect when:
Just make sure the URL is public and accessible.
So far, we displayed images using Python code. But what about documentation?
Colab supports Markdown cells. You can embed images inside them.
Click + Text to add a Markdown cell. Then use:
 Example:
 The image will appear inline. Clean. Beautiful. Great for reports.
You can also resize using basic HTML inside Markdown:
<img src="image_url" width="300"> This gives you more control over size.
Image not found in postmetaSometimes things do not work. Don’t panic. Here are quick fixes.
!ls Here are some tips to make your life easier:
Also remember: Colab sessions reset. If something is important, store it in Drive.
Here is a quick comparison:
Each method has its moment. Pick what fits your goal.
Working with images in Google Colab is not scary. It is actually fun. You upload. You display. You customize. Done.
The key idea is simple:
That’s the whole story.
Whether you are building a deep learning model, writing a tutorial, or just experimenting, inserting images into Colab notebooks is easy once you know these tricks.
Now open a notebook. Upload an image. Try each method. Play with resizing. Add titles. Break things. Fix them.
Learning sticks when you experiment.
And remember. In Google Colab, images are just one upload away.
Editing your video is only half the job. Exporting it the right way is what…
In an era where consumers are constantly connected and competition for attention grows fiercer by…
Motion graphics have transformed the way creators tell stories online. Whether you’re designing Instagram Reels,…
There is nothing more frustrating than settling in for Monday Night Football, snacks ready, only…
YouTube intros are like handshakes. They set the tone. They spark curiosity. And they help…
Seeing the message “Sending as Google username” when you try to send a text message…