I am trying to insert an image in Google Colaboratory (markdown) already saved in Google Drive using this expression 
but it doesn't work. For example, the Colaboratory markdown manual shows how to insert a photo inline with this example An inline image: 
. Ok, that is a photo from internet, but, when I replace that photo for one already saved in my Google Drive it doesn't appear.

- 581
- 1
- 4
- 4
-
Welcome to Stack Overflow, Please [Read](https://stackoverflow.com/tour) – Arash Jun 03 '18 at 21:50
-
Your question is hard to answer without a little more information. How exactly is it not working? – Dux Jun 03 '18 at 22:52
-
For example, the Colaboratory markdown manual shows how to insert a photo inline with this example An inline image: `` . Ok, that is a photo from internet, but, when I replace that photo for one already saved in my Google Drive it doesn't appear `![myphoto] (https://linktomyphotoingoogledrive)`. – Igor Gomez Jun 03 '18 at 23:06
-
Possible duplicate of [How do I display images from Google Drive on a website?](https://stackoverflow.com/questions/15557392/how-do-i-display-images-from-google-drive-on-a-website) – Tim Diekmann Jun 04 '18 at 00:15
12 Answers
If you have a link like this, then I've got a solution.
https://drive.google.com/file/d/-------/view?usp=sharing
- In Google Drive, right-click on the picture
Choose 'Get a sharable link'
Click to 'Copy link'. You need reader permissions. Just need the id of the image.
In my case my link is:
https://drive.google.com/file/d/1xDrydbSbijvK2JBftUz-5ovagN2B_RWH/view?usp=sharing
Now we need to copy JUST the image id:
1xDrydbSbijvK2JBftUz-5ovagN2B_RWH
We will use this base link to generate your link with the image id:
https://drive.google.com/uc?export=view&id=your_id
We then copy the id in the link:
https://drive.google.com/uc?export=view&id=1xDrydbSbijvK2JBftUz-5ovagN2B_RWH
Finally, to place as an image in Google Colab:


- 840
- 5
- 6
-
3Thank you sir. Btw I made a function to convert the links to shareable ones in case you have many of them: def image_linker(links): ids = [] for link in links: id = link[32:65] ids.append(id) new_links = [] for i in ids: id_link = 'https://drive.google.com/uc?export=view&id='+i new_links.append(id_link) return new_links – fega_zero Dec 07 '20 at 19:54
-
2You may need to **allow 3rd party cookies for the image to appear** ! This gave me a 1h headache while trying all combination of uc?export=view&id=..., uc?id=... and so on. – cbo Feb 26 '21 at 11:42
-
1Your answer only work with this simple modification here: 1. right click the image in your google drive and click `Get Link`. 2. choose `Any one with this link`, then click copy link, e.g. https://drive.google.com/file/d/1VbCjqRtQRun8lv7xOcBiZd7FidqU9lyh/view?usp=sharing. Here `1VbCjqRtQRun8lv7xOcBiZd7FidqU9lyh` is the id you need for the next step. 3. put this into your colab Text cell:  – Paul.j Jul 26 '21 at 14:20
I tried all the answers above and nothing worked because of a small change Google has created recently(at the time of writing this post). If you click on "Get Shareable link" and paste it, it would look something like this:
https://drive.google.com/open?id=12BumFEqzKxc9mog8tYuUqvpxf10ot6W3
Now just change the open?id to uc?id and it will instantly work.

- 27,060
- 21
- 118
- 148

- 544
- 5
- 11
-
2
-
5Was there a change with google drive? When I try I received https://drive.google.com/file/d/{IDRETRACTED}/view?usp=sharing – ffejrekaburb Jun 07 '20 at 19:03
-
1google drive changed the link structure, there is no `open` in the link anymore – Alon Gouldman Jul 31 '20 at 05:08
According to the answers here


- 37,818
- 16
- 123
- 144
-
If you think an answer from a different question answers this question. then this question is very likely a duplicate and should be flagged/voted to close as duplicate, not answered. – Makyen Jun 04 '18 at 00:13
-
@Makyen I've never try flagging before. I'll try it next time. For this question, it's not an exact duplicate. The question I refer to is for image url in general. But this question is also about Jupyter/Colab markdown. – korakot Jun 04 '18 at 00:45
-
@KorakotChaovavanich Yeah, I looked over the answers there & agree on it's own it's not a perfect dup, although it reasonably might be considered so (Igor already has Markdown for an image). However, that's why it's possible to add multiple duplicate targets to a question (i.e. this question is really two questions: "what's the markdown to display an image?" and "What's the externally accessible URL for a Google Drive asset (e.g. an image)?". If people close it with two duplicate targets, then two will be listed. Alternately, a gold tag badge holder can close it with <= 5 duplicate targets. – Makyen Jun 04 '18 at 01:29
From the next 3 formats only the first one worked for me:




- 42,291
- 14
- 186
- 151
-
For me, taking the Google Drive link (right click, get shareable link) and pasting, then changing 'open' to 'uc' worked. – eafpres Dec 08 '19 at 01:17
-
1They should post this in google colab tips. after 100 tries, this one worked!! – Masih Jul 03 '20 at 22:19
Here is an example using plain html instead of markdown.
<figure>
<center>
<img src='https://drive.google.com/uc?id=1Rb6oXW3KufLApvID5MwxsknpoON2CkQ_' />
<figcaption>Image Caption</figcaption></center>
</figure>
This way, you can also center the image, add captions etc

- 1,423
- 17
- 25
This below method works for me:
- Upload the image on google drive.
- Enable link sharing (Right click on image > Get shareable link)
- Change access type from 'Restricted' to 'Anyone with link', keep role as 'Viewer', click 'Done'(pop up should close).
- Double click on image, Spot 'More actions' icon(top right corner, 3 vertical dots).. click on it and next select 'Open in new tab' from the more action menu, a new windows opens.
- Now again, spot 'More actions' icon(top right corner, 3 vertical dots).. click on it and select 'Embed item'. It will give you a HTML 'Embed snippet'.
- Copy that HTML snippet and paste it in your Colab noteboook inside a markdown or code cell.
If you use a code cell, you can use magic function %%html (change iframe width and height for your needs).
%%html
<iframe src="link_placeholder" width="600" height="300"></iframe>

- 239
- 4
- 3
-
This worked for me! The crucial part that all the above answers seem to miss is changing the **access type** from 'Restricted' to 'Anyone with link' – joshua Jan 10 '21 at 03:59
-
Wish I could upvote more than once. This is the only solution which worked for me. – creative Mar 08 '23 at 17:19
Unfortunately, I have tried the methods above but they didn't work for me. Then I have tried simply right-clicking on the picture that I want to display on colab, and choose 'Get a sharable link', then the link is automatically copied to my clipboard:
The link will be something like
https://docs.google.com/uc?id=-----
Then using colab's picture inserting button, and insert that link to the (https://) part

worked like a magic!
However, if you get a link like this
https://drive.google.com/file/d/-------/view?usp=sharing
after making picture public, it somehow doesn't work.
-
Key is to upload the files directly into Google Drive. If they are uploaded in a zip file and then unzipped, I have gotten the /file/ mess that you describe. But uploading directly has them in the /open/ format where the switch to /uc/ works. – Reid Apr 05 '20 at 21:42
I tried all of the above methods, and nothing works for me. However, there is a workaround that bypasses the use of Google Drive altogether: Simply insert the image as Base64 data in normal HTML like so:
<img src='data:image/png;base64, ...lots of base64-data.. style="max-width:100%;" />
If you, for example, are using draw.io to draw a diagram that you want to include, there is a handy option for embedding data (under file->embed). If you choose "image" in this menu, you'll get a pop-up with the relevant code for you to copy. Otherwise there are image to base64-converters online that you can use.
The downside of this method is that you'll end up with a lot of data to paste. However, if you use a dedicated cell for this purpose, there won't be any need to edit that cell ever again.
(As a side note, this method works in most Markdown editors if you for some reason are unable to include an image file. Sometimes it will also work to use SVG data instead of base64, but this does not work in Google Colab.)

- 41
- 6
Once you get the public URL of the image, you can insert it in a Markdown cell
With

Or in a Code cell
(this trick is just in Colab, as far as I know)
With
#@markdown 
So you can have Markdown within a code cell.

- 2,071
- 21
- 37
Here are my solutions. I liked the first one more.
First Solution :
Step1: First use a wget to fetch the picture, do not use svg file! just png
!wget https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Jupyter_logo.svg/207px-Jupyter_logo.svg.png
Run the code
Step2: Get the name of the file from last line '207px-Jupyter_logo.svg.png', after you run the wget.
from IPython.display import Image
Image("207px-Jupyter_logo.svg.png")
Run the code!
Second Solution: use the code below and use png file
from google.colab.patches import cv2_imshow
!curl -o logo.png https://colab.research.google.com/img/colab_favicon_256px.png
import cv2
img = cv2.imread('logo.png', cv2.IMREAD_UNCHANGED)
cv2_imshow(img)
So enjoy :)
- Solution for svg or other type of files

Anyway, use your link :)
3rd from Github_md_guideline

- 69,473
- 35
- 181
- 253

- 21
- 2
Link to shareable image is restricted to unique code associated to that picture. Once you update the picture (happens), then you need to update the link too.
Alternative ways are described here . My solution is given there too, so I will not copy past it here.

- 303
- 5
- 9
You can simply copy the picture in the clipboard and paste it in a markdown cell

- 593
- 6
- 17
-
This does work, but is imports a huge amount of data into the cell using `(data:image/png;base64,iVBORw0KGgoAAAANSUhE ... lots of text! ...)`. Also you can't center, set size, etc. – Prof Huster Sep 22 '21 at 12:53