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

Adam Nielsen a.nielsen at shikadi.net
Fri Apr 21 02:14:27 PDT 2023


> 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
> 
> 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
> [...]
> 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.

I ended up logging a bug request for this but it turns out it was my
own inexperience with QGIS.

It turns out that you can go into the layer properties, and under the
"Attributes Form" item, you can set whether a filename field should use
a relative or an absolute path.

This defaults to 'absolute', so changing it to 'relative' fixed the
problem.

I used the attribute editor and some string functions to do a bulk
search-and-replace to remove the leading path elements from all
features in the layer, turning them all into relative links.

The preview image still shows in the attribute editor, and I can use
the browse button and get a relative path returned upon file selection.
So with this small change, everything works fine now with relative
paths.

I did have to update the HTML map tip to include the project path as
per my original message:

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

And this works fine on whatever Linux machine I open the project on.  I
guess it won't work on a Windows machine though (see the other messages
in this thread) but I don't have one handy to confirm.

Cheers,
Adam.


More information about the QGIS-User mailing list