5

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?

5

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

  • Indeed, the attribute table contains a relative pathname, but the html display still requires the root folder c:/temp/ to be defined. Is it possible to adapt this to a situation where the only information known about the image source is relative to the directory containing the QGIS project? – user25976 Mar 28 '14 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.