Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert an inline image in Google Colaboratory from Google Drive

I am trying to insert an image in Google Colaboratory (markdown) already saved in Google Drive using this expression ![Text](https://xxxx) but it doesn't work. For example, the Colaboratory markdown manual shows how to insert a photo inline with this example An inline image: ![Google's logo](https://www.google.com/images/logos/google_logo_41.png). 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.

like image 994
Igor Gomez Avatar asked Jun 03 '18 20:06

Igor Gomez


People also ask

How do you add a picture from Google Drive to Colab?

First, open google drive & upload the image on the drive. Select the uploaded image, right-click on it, get a sharable link & copy it. Open Google Colab Notebook & add text block where you want to include the image. The general code to include an image is given below.

How do you import from Google Drive in Colab?

You can import files module from google. colab . Then call upload() to launch a “File Upload” dialog and select the file(s) you wish to upload. Once the upload is complete, your file(s) should appear in “Files explorer” and you can read the file as you would normally.

How do I display an image in Google Colab?

The function cv2. imshow() is used to display an image in a window. This function takes 2 arguments. The first argument is the window name (Specify unique window names to display multiple images) and the second argument is the image to be displayed.


1 Answers

If you have a link like this, then I've got a solution.

https://drive.google.com/file/d/-------/view?usp=sharing 
  1. In Google Drive, right-click on the picture
  2. Choose 'Get a sharable link'

    enter image description here

  3. Click to 'Copy link'. You need reader permissions. Just need the id of the image.

    enter image description here

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:

![](https://drive.google.com/uc?export=view&id=1xDrydbSbijvK2JBftUz-5ovagN2B_RWH) 
like image 157
Alejandro Núñez Arroyo Avatar answered Sep 23 '22 13:09

Alejandro Núñez Arroyo