[Qgis-user] How to have photos appear in HTML tips *and* the attribute editor?

Adam Nielsen a.nielsen at shikadi.net
Sun Apr 16 08:25:26 PDT 2023


Hi all,

I have imported some geotagged photos via the Processing toolbox, and
now I have a layer with a bunch of photos that have absolute paths:

  /project/example/photos/2023-01-01/img1.jpg

In the layer I have specified this as:

  <img src="file://[% "photo" %]" />

This works fine:

 1. When I open the attribute editor form, the actual image is loaded
    and shown in the form.
 2. When I hover over the feature on the map, the tip appears and the
    photo is shown.

However, when I move the project to a different computer, this no
longer works, because the project and photos are located under a
different path, even though the photos are in the same path relative to
the project file.

If I change my layer so that the "photo" field is a relative path (by
stripping off the leading path and adding a dot, making the filename
"./photos/2023-01-01/img1.jpg"), and change the HTML tip to this:

  <img src="file://[% @project_folder + '/' + "photo" %]" />

Then the map tips show the correct photo regardless of the path.
However the attribute form is no longer able to display the photo, and
if I use the browse button to select a different file, it saves the
absolute path again.

Is there some way to achieve one of the following:

  1. Have the attribute editor display and populate fields with
     relative paths instead of absolute paths.

  2. Use an expression to trim off the project path from the front of a
     field, so the HTML tip can extract a relative path from the
     absolute path stored in the layer.

The first option is probably preferable, but I can't seem to find
anything to make the attribute editor work with relative paths.

Many thanks,
Adam.

P.S. I have seen many things saying you must specify the URL as
file:/// with three slashes to make it work under Windows, but under
Linux you must have only two slashes.  It would be nice if any solution
to this worked across all platforms.


More information about the QGIS-User mailing list