I maintain a layer in my project that indexes geotagged research photos. Right now, the layer (in a gpkg) has an attribute
PhotoPath which points to the photos stored separately on disk. I then use a QML or HTML widget in the layer attribute form to display the photo. This widget (HTML version) has a
document.write(expression.evaluate("\"PhotoPath\"")); embedded in a
<img src="..."> tag.
For portability and version control, I'd like to store the actual photos inside the gpkg.
Since version 3.8, QGIS allows storing binary (blob) data inside a gpkg and accessing it with a binary widget. Unfortunately, so far it seems this widget only allows importing or exporting the blob data, not other manipulation. Any ideas how to display it as an image?
I've done a manual proof of concept of the following klugey solution, but I hope there's something better.
Storing the photo in the gpkg not as a binary blob, but in a base64 encoded text representation.
<img src="...">with a
<img src="data:image/jpeg;base64,...">to paste in the picture as a data URL.
To do this fully, I'd have to implement the base64 encoding as a PyQGIS action and/or processing algorithm; and muck around with various escaped quotes in the HTML widget. It's storage-space and computationally wasteful, and I'm not sure if there's an upper limit on the data URL length. Any better approach I'm missing?