[GIS] QGIS html annotation relative paths

file pathhtmlqgis

I find the QGIS html annotation tool is very useful for quickly accessing a combination of key data attributes and photos. I am having trouble using relative paths for images.

This doesn't work:

<img src="[% html_src %]" /> 

a.k.a.

<img src="/Image/Picture.JPG" />

I'm wondering if it's possible to employ a QgsProject.instance() in the QGIS Macro option under project properties. I don't know html very well, so I'm wondering how I could link the relative pathname to the project path using something like this:

proj = QgsProject.instance()
UriFile = str(proj.fileName())
pathname = str(os.path.dirname(UriFile))

How can I concatenate this in the html display option?

Best Answer

I think you can solve this problem, if you adapt your situation, like in the example bellow.

Presuming this is how it looks the vector layer's attribute table:

enter image description here

Here's the images' storing folder:

enter image description here

And this is the annotation.html :

<b> [% "name" %] </b>
<br />
<img src=file:///c:/temp/images/[% "img_src" %].png />

Eventually, here's the result:

enter image description here