How do I render a local image in Looker?

Knowledge Drop

Last tested: March 2021

Looker expects a public URL for your image. So make sure that wherever you store it is publicly accessible. Then, you can call it in LookML like so:

view: view_name { dimension: field_name { html: <img src=”http://www.acme.com/product_images/my_image.jpg” /> ;; }}

This help center article goes more in depth on the modeling.

It's not possible to use a local image on your computer, or on the Looker server. It is also not possible to use non-public URLs, as Looker will have no way to authenticate.

This content is subject to limited support.                

Comments
Irvin
Community Visitor

Hi guys, i wanted to know if it was still impossible to use a local image ?

I’m currently using images host on my server, but whenever i try to export dashboard containing those images, it export with no images.
 

sam8
Staff

@Irvin That’s correct. It’s not possible to use a local image - either on your own server or on the Looker server.  You’ve gotta use a URL.

If you can access Looker’s product feedback system, then you can upvote this feature request and leave more details with your use case!

nicohein
New Member

Hi @Irvin, @sam8 

If you need to add an image that should not be hosted on a public domain you can insert it as a base64 encoded string. This works in LookML as well as Text tiles. Please be aware that for larger images this renders the Text tile popup unresponsive. So, please make sure you have the content ready to paste and avoid editing within the online interface.

First encode the image into a base64 string (e.g. using python):

python -mbase64 image.png | tr -d '\n' > b64encoded.txt

Then insert a tile with a content like the following:

<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Grid US" />
Irvin
Community Visitor

Hi, @nicohein 

this solution works as intended with Text Tiles, but not with LookML.

1b28dd1b-55ec-4136-b51c-3622be63a463.png



I tried with the img you provided (which works well in a text tiles as i said), and this renders nothing but a white screen.

 

e592d840-dda8-4314-b71a-aab336b4b95a.png



Do you have any solution to put base64 img in a dimensions in lookML ?

and thanks for the later response !

 

nicohein
New Member

Hi @Irvin,

unfortunately I can be of very little help for this one. I just had a quick look and it seems like Looker has some validations for the source values.

While the following renders as it should:

<img src="dataimage" alt="Test" />;

Adding either a colon or a semi-colon makes src parameter disappears:

<img src=";" alt="Test" />; <!-- renders as --> <img alt="Test" />;
<img src=":" alt="Test" />; <!-- renders as --> <img alt="Test" />;

If I add a space the output indicates that Looker also applies url encoding which is not useful in your case:

<img src="data image" alt="Test"> <!-- renders as --> <img src="data%20image" alt="Test">

I would hope your images are not secret and you can do something like using GitHub e.g. 

dimension: logo {
label: "Logo"
type: string
sql: "" ;;
html: <img src="https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/svgs/solid/address-book.svg" alt="Test" />;;
}

or using a public bucket to host your static content.

sidsenthil
New Member

We had to remove the space, as so

  dimension: images {
type: string
sql: BASE64(${TABLE}.content) ;;
html: <img src="data:image/jpeg;base64,{{value}}"/>;;
}
Version history
Last update:
‎04-05-2021 09:09 AM
Updated by: