1

BACKGROUND:

At 3.18.3, this is my first experience with BLOB fields. I have created a standalone Geopackage table that contains a BLOB field (I'm not sure why Layer Properties calls it a QByteArray, but I'll save that question for another day...)

enter image description here

I open the table and edit, adding digital photographs (one .jpg per table row) to the BLOB field by right-clicking the dropdown triangle and selecting Embed File..., then browsing to the jpg's path location and selecting the file. I then save my edits:

enter image description here

PROBLEM:

When I switch the table to Form Vew, the images stored in the table can be viewed, which is very useful. However, some of the photos (about 20%) are rotated 90 degrees to the left (always to the left), as shown below. Additionally, one of the images (out of approximately 150) is rotated upside-down by 180 degrees.

All of the images rotated to the left happen to have been taken in portrait mode (but note that the majority of portrait-mode photos display correctly). The single upside-down photo was taken in landscape mode.

I cannot find any other pattern as to why these particular photos are rotated. The rotation can occur to different photographers, cameras, and dates. Sometimes the rotated photo is one of several taken at the same time and location - where the other photos in the sequence are not rotated.

Further, all of the rotated photos display correctly when viewed in Windows Paint or Irfanview!

Restarting QGIS does not solve the problem.

Why is this rotation happening, and how can it be prevented?

enter image description here

2

Commonly images have some metadata embed on it called "EXIF" data. This metadata contains information about things like when the picture was taken or the "orientation" of the image.

Many software like the file explorer in Windows or Linux, or image viewers read this data to automatically rotate the image according to the EXIF orientation parameter. So you can see "in the right way" even when the image was taken in a different orientation.

But QGIS does not take the EXIF orientation metadata into account.

One easy way to handle this situation is manipulate the image in an image editor before inserting it in the geopackage, to rotate the image.

If you are confortable with the console an easy way to make this in batch is use ImageMagick.

mogrify -auto-orient your-image.jpg

IrfanView users, as @stu-smith comments, also have a command to automate the process:

i_view64.exe filename.jpg /jpg_rotate(6)
2
0

As @Francisco Puga's answer states, the issue is likely EXIF rotation, which QGIS' native display does not support.

If you want a workaround that fixes this on the fly, by rendering the image in HTML and QML, see my question and the several answers at Display photo stored as blob in GPKG, even though this is for an earlier version of QGIS.

Note any such on-the-fly solution needs to either import the EXIF orientation tag as an attribute in your layer, or use a library to read it from the data, or you will need to manually flag the images needing rotation in your layer. So this may ultimately not be less work than just fixing the rotation in an image editor. Nevertheless, sharing in case it is preferable in your instance.

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.