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

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.

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:
![](https://drive.google.com/uc?export=view&id=1xDrydbSbijvK2JBftUz-5ovagN2B_RWH)

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.

According to the answers here
![](https://drive.google.com/uc?export=view&id=XXX)

From the next 3 formats only the first one worked for me:
![](https://drive.google.com/uc?export=view&id=0B3SU50kcW4Q4WFlla00tX3hkdkE)
![](https://drive.google.com/file/d/0B3SU50kcW4Q4WFlla00tX3hkdkE)
![](https://drive.google.com/open?id=0B3SU50kcW4Q4WFlla00tX3hkdkE)

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

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
![picture](your link)
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.

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>

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.)

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
![This is an image](https://.......svg)
Anyway, use your link :)
3rd from Github_md_guideline

Once you get the public URL of the image, you can insert it in a Markdown cell
With
![Image in a markdown cell]( https://i.imgur.com/6Z1i8zF.png)
Or in a Code cell (this trick is just in Colab, as far as I know)
With
##markdown ![Image in a code cell]( https://i.imgur.com/6Z1i8zF.png)
So you can have Markdown within a code cell.

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.

You can simply copy the picture in the clipboard and paste it in a markdown cell

Related

Google Sheet & App Script : how to get image from a link preview?

I am trying to reproduce a RSS reader like Feedly with Google Sheet and displaying with Glide as an app on my mobile phone.
Everything's fine with IMPORTFEED() function with titles, description, URL.
But it seems this function doesn't allow pictures to be displayed even if they are in the feed (which is not all the time).
So I am looking for a way to extract the main image from a blog post... the one displayed when you hover on a link in a Google Sheet cell.
I would like to get the link of that image displayed in the link preview and put that link in another cell.
Here is an example:
I tried IMAGE()
and also IMPORTXML when there is an image in the RSS feeds (but not all of them do... so I stopped)
Is it possible in Google Sheet to get the main image from the one displayed in the link preview ?
For instance, one of the blog I want to extract the main picture of a blog article would be Creajv (URL : https://creajv.com/ ; Feed : https://creajv.com/feed/)
So the IMPORTFEED() function I did in Google Sheets was :
=IMPORTFEED("https://creajv.com/feed/";"items";FALSE;3)
Which stands for :
=IMPORFEED(...) the function to import feeds from an URL
"items" the way to pull every data there is in the feed (you can use other parameters and can see all the possibilities on the GoogleFormulas documentation)
FALSE because I don't want the headers to be included
and the number 3 because I want only the last 3 results displayed.
And it displays perfectly : author, description, URL, date
But I did a little digging in Google and found that basically IMPORTFEED() cannot get images from feeds, even if it is added by the author of the blog (he has to add a feature to do it).
So I am now trying to see if there is another way which is not IMPORTFEED() to get every time the main image of a blog post.
And I saw Google Sheet is able to pull instantly it when I copy paste the URL of a blog article within a cell for instance for Creajv :
Print screen of the image I get when I click in the cell which contains the post URL
So my thoughts would be that I can pull the author, date, description etc. with IMPORTFEED (which works perfectly every time) and use a formula on the cell with the URL to get in another cell the URL of the picture pulled from the one in the link preview.
Two other possibilities might also be with Google App Script :
creating with the App Script a custom function
or creating a script pulling the image in a cell every time a new row is added via the IMPORTFEED() function.
Functions only, as Apps Script doesn't run on mobile Apps
How about this solution? I checked the website and inspected the image from the thumbnail.
Luckily, the structure is simple:
<div class="article-image">
<img src="https://creajv.com/wp-content/uploads/2020/11/HighresScreenshot00000.png" alt="Concours de Level Design avec Unreal Engine, du 11/11 au 05/12/2020">
</div>
You can get the url with IMPORTXML, and apply IMAGE to it:
=IMAGE(ImportXml("https://creajv.com/2020/11/08/concours-de-level-design-avec-unreal-engine/", "//div[#class='article-image']//img/#src"))
Since you are already retrieving the post url with your previous formula, change the source url by the correspondent cell:
=IMAGE(ImportXml(C1, "//div[#class='article-image']//img/#src"))
For example:

Cannot add inline image/picture to a Rich Text control

I have a Rich Text control bound to a Body field in my Domino Document data source ... all is good for formatting text , :) emoticons and the usual stuff. The problem is when I try to paste or upload an inline image I get the following error shown in the inline image (hmmmm, works here) ...
Most likely a mis-understanding of the steps:
Select the file
Click on upload image (<-- that one gets lost on lots of users)
Click OK
For a more advanced user experience:
Use the RichText Editor Evolution from OpenNTF. That makes your life much easier.

Confluence export dynamic PDF title

I am using Confluence 4.0.3, I am trying to create a PDF layout/stylesheet so that it would grab the main title from the page content and move it to the title page.
What I have tried so far:
use the way that confluence suggests - it did not work well at all because it came with extra toc (np, I can hide it) and extra page content because it requires me to export from the parent level for it to work
I define a macro which contains the page title and I can use css to make it land on the title page. This works however if I was to export multiple docs this could pose a issue
Style the h1:first-child, this works but again on multiple docs this would be an issue.
Question: Is there a good way to do this on multiple doc exports? If not, does the page title have its own class that I can target instead of the h1:first-child? I tried h1.pagetitle (in their documentation) but it does not work, thanks
I used a user defined macro to put the title in and use the PDF export css to position it on the title page. This works as long as you are only exporting 1 document at the exporting level. If you are exporting 2 or more docs from the same exporting level then you can only define 1 of the macros or else they will all be at the same position on the title page.
This seems like the easiest way I found to implement something like this.
I would try employing a minor work-around. You could use a .asp page, which is located off of confluence, to pull the the pdf title and display it how you like. Then you can use an html-include macro to display the .asp page, and the pdf title it shows, wherever you like on confluence.

Joomla/Seblod Display Image Thumbnail Only, Link to Lightbox

I am using Joomla and Seblod. I would like to create a gallery of thumbnails only, tiled next to one another and when clicked it will open each image into a lightbox (fancybox) and display larger image and description.
Problem I'm having is that when I try to display only the image thumbnails, I get the label "Image" or whatever I enter into Seblod. I just want plain image thumbnails, no text or any description but when clicked it opens them in the lightbox. I'm sure this is child's play, but confusing for a a beginning Joomla user like myself.
Any help would be appreciated, thanks.
There is built-in Lightbox functionality in Seblod, but it takes a few steps to make it work. It is even better if you use a custom template, because then you can add regular PHP functions to process your photos.
In any case, to get started, look at the tutorial I wrote on this subject: http://www.seblod.com/support/documentation/seblod-2x/fields/typo/1710-create-a-simple-gallery-with-fieldx-field.html

Insert an image with a link in a PDF using PDFBox

I have multiple PDFs and I want to insert a logo on every page which links to http://xyz.com (that is, clicking on the logo opens up xyz.com in the browser).
Also, I want to insert some text 'Click Here to view this page at xyz.com' next to the logo where 'Click Here' is a link (different link on every page, like http://xyz.com/show.php?id=76&page=3)
I have been able to add the logo and the text but could not figure out how to make the text a link.
I had posted this on pdfbox-users mailing list also and a pointer to the solution was posted there by Hesham G. Link

Resources