Bug 515664 - Wrong Exif orientation in stored image files when auto rotating
Summary: Wrong Exif orientation in stored image files when auto rotating
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Metadata-Orientation (other bugs)
Version First Reported In: 8.8.0
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-02-06 23:56 UTC by Markus S.
Modified: 2026-04-15 19:26 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 9.0.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus S. 2026-02-06 23:56:45 UTC
This bug happens when auto rotating images according to their exif rotation while using xmp-sidecars. It's triggered by importing images from camera/storage or using Item/Rotate/Auto rotate.

Step to reproduce
1.) Configure Digikam as follows
  Metadata/Sidecars/Reading and Writing to Sidecars
    [x] Read from sidecar files
    [x] Write to sidecar files
       => Write to XMP sidecar only
  Metadata/Behavior/Reading and Writing Metadata
    [x] Use lazy synchronization
    [x] update filemod. timestamp ...
    [x] Rescan file...

2.) Import an image with exif orientation = 6 (CW)  
  (6 is just an example, the bug generally happens with orientations != 1)

- Image data is rotated according original exif rotation and image file is saved 
- Exif data of saved image file still contains old - now invalid - orientation
  => Data inside the image is rotated to 1 (Normal)
  => New image is saved still with Exif orientation 6 (CW) 
- (only) the corresponding xmp File contains the now correct exif rotation value 1 = normal
  
  result:
- Digikam still displays the image in correct orientation, either due to caching or only evaluating only the xmp file  - to make digikam display the image in the now wrong orientation, the .xmp has to be deleted and then the metadata must be re-read from the image
- other image viewers which ignore the xmp file show the image rotated once more => that's odd.
  
As a workaround, the wrong metadata can be easily fixed using
  exiftool -P  -n -Orientation=1  -overwrite_original  FILENAME.JPG

Version Info:
digiKam: 8.8.0
KDE Frameworks: 6.22.0
Qt: Using 6.10.1 and built against 6.10.1
openSUSE Tumbleweed (Xcb)
Build ABI: x86_64-little_endian-lp64
Kernel: linux 6.17.9-1-default
Comment 1 Maik Qualmann 2026-02-08 08:10:14 UTC
This isn't a bug if you enable "write only in sidecar" in that case. The original image won't be changed, nor will the orientation flag.

Some users enable "write only in sidecar" to avoid changing the original image. We can't simply make an exception for the orientation flag here.

Maik
Comment 2 Maik Qualmann 2026-02-08 15:12:02 UTC
My comment wasn't entirely accurate. When we rotate an image, we also write the orientation flag, provided the option is enabled.

I can't reproduce the problem with the auto-rotation function here; the orientation flag is correctly set to "Normal."

Please provide a sample image where the problem occurs.

Maik
Comment 3 Markus S. 2026-02-08 21:05:31 UTC
Maik, since sample images are large I just sent you a PM containg a link for downloading a sample image. You'll find two folders: 

a) after-digikam-import-with-autorotate 
  also containing the digikam generated .xmp. 

b) original-from-camera
The second is just copied outside digikam.
Comment 4 Markus S. 2026-02-10 22:19:10 UTC
I started digikam with debug logging activated and imported the test image once more. Please find the log at the end of this comment.

Interestingly, in the log digikam writes after the first stage of import:

  digikam.metaengine: Loading metadata with "Exiv2" backend from "/tmp/testalbum/DSC02035.jpg"
  digikam.general: mimetype =  "JPEG"  ext =  "JPG"
  digikam.metaengine: Exif.Image.Orientation tag set to: 1

But that's not true per exiv2:

% exiv2 -pe DSC02035.jpg | grep -i orient
  Exif.Image.Orientation                       Short       1  6
  Exif.SonyMisc3c.CameraOrientation            Byte        1  6
  Exif.Thumbnail.Orientation                   Short       1  6

This is the full log (directory names edited for privacy):

digikam.import: Log ( ""   "" :  "Verbindung mit der Kamera wird hergestellt ..."
digikam.import: Supported features for "Bilder auf USB-Datenträger „TRALALA“ unter /run/media/markus/TRALALA (1,9 GiB)"
digikam.import:   Thumbnails: true
digikam.import:   Delete: true
digikam.import:   Delete dir: true
digikam.import:   Upload: true
digikam.import:   Mkdir: true
digikam.import:   Image capture: false
digikam.import:   Image capture preview (liveview): false
digikam.import: Log ( ""   "" :  "Verbindung hergestellt."
digikam.geoiface: ----
digikam.metaengine: Loading metadata with "Exiv2" backend from "/run/media/markus/TRALALA/DCIM/DSC02035.jpg"
digikam.rawengine: Failed to load embedded RAW preview
digikam.geoiface: QVariant(QPersistentModelIndex, QModelIndex(0,0,0x55efeb2e34e0,Digikam::ImportFilterModel(0x55efea67fdc0))) QSize(382, 510)
digikam.metaengine: Loading metadata with "Exiv2" backend from "/run/media/markus/TRALALA/DCIM/DSC02035.jpg"
digikam.import: Downloading:  "DSC02035.jpg"  using  "/tmp/testalbum/Camera-oVojoI-d86cdde5.digikamtempfile.DSC02035.jpg"
digikam.import: Set metadata from:  "DSC02035.jpg"  using  "/tmp/testalbum/Camera-oVojoI-d86cdde5.digikamtempfile.DSC02035.jpg"
digikam.metaengine: Loading metadata with "Exiv2" backend from "/tmp/testalbum/Camera-oVojoI-d86cdde5.digikamtempfile.DSC02035.jpg"
digikam.import: Metadata template title: "_REMOVE_TEMPLATE_"
digikam.metaengine: MetaEngine::metadataWritingMode 1
digikam.metaengine: Will write XMP sidecar for file "Camera-oVojoI-d86cdde5.digikamtempfile.DSC02035.jpg"
digikam.metaengine: wroteComment:  false
digikam.metaengine: wroteEXIF:  true
digikam.metaengine: wroteIPTC:  true
digikam.metaengine: wroteXMP:  true
digikam.metaengine: Metadata for file "Camera-oVojoI-d86cdde5.digikamtempfile.DSC02035.jpg" written to XMP sidecar.
digikam.metaengine: Loading metadata with "Exiv2" backend from "/tmp/testalbum/Camera-oVojoI-d86cdde5.digikamtempfile.DSC02035.jpg"
digikam.import: File "/tmp/testalbum/Camera-oVojoI-d86cdde5.digikamtempfile.DSC02035.jpg.xmp"  has a sidecar, renaming it to  "/tmp/testalbum/DSC02035.jpg.xmp"
digikam.general: Event is dispatched using KDE desktop notifier
digikam.maintenance: scan mode: ScheduleCollectionScan ::  QList("/tmp/testalbum")
digikam.metaengine: Loading metadata with "Exiv2" backend from "/tmp/testalbum/DSC02035.jpg"
digikam.dimg: "/tmp/testalbum/DSC02035.jpg" : "JPEG" file identified
digikam.database: Adding new item "/tmp/testalbum/DSC02035.jpg"
digikam.metaengine: DateTime (Exif digitalized): QDateTime(2026-02-08 21:38:54.000 UTC Qt::UTC)
digikam.metaengine: DateTime (digitization date): QDateTime(2026-02-08 21:38:54.000 UTC Qt::UTC)
digikam.database: Scanning took 61 ms
digikam.database: Finishing took 20 ms
digikam.general: Event is dispatched using KDE desktop notifier
digikam.metaengine: Loading metadata with "Exiv2" backend from "/tmp/testalbum/DSC02035.jpg"
digikam.general: Trying to get thumbnail from "/tmp/testalbum/DSC02035.jpg" ( "image" )
digikam.general: Trying to get thumbnail with Exiv2 for "/tmp/testalbum/DSC02035.jpg"
digikam.general: Trying to get thumbnail with DImg preview for "/tmp/testalbum/DSC02035.jpg"
digikam.general: mimetype =  "JPEG"  ext =  "JPG"
digikam.general: mimetype =  "JPEG"  ext =  "JPG"
digikam.metaengine: Loading metadata with "Exiv2" backend from "/tmp/testalbum/DSC02035.jpg"
digikam.general: mimetype =  "JPEG"  ext =  "JPG"
digikam.metaengine: Exif.Image.Orientation tag set to: 1
digikam.metaengine: MetaEngine::metadataWritingMode 1
digikam.metaengine: Will write XMP sidecar for file "JpegRotator-nnEXjF-c0a668dc.digikamtempfile.jpg"
digikam.metaengine: wroteComment:  false
digikam.metaengine: wroteEXIF:  true
digikam.metaengine: wroteIPTC:  true
digikam.metaengine: wroteXMP:  true
digikam.metaengine: Metadata for file "JpegRotator-nnEXjF-c0a668dc.digikamtempfile.jpg" written to XMP sidecar.
digikam.metaengine: Loading metadata with "Exiv2" backend from "/tmp/testalbum/DSC02035.jpg"
digikam.metaengine: Exif.Image.Orientation tag set to: 1
digikam.metaengine: MetaEngine::metadataWritingMode 1
digikam.metaengine: Will write XMP sidecar for file "DSC02035.jpg"
digikam.metaengine: wroteComment:  false
digikam.metaengine: wroteEXIF:  true
digikam.metaengine: wroteIPTC:  true
digikam.metaengine: wroteXMP:  true
digikam.metaengine: Metadata for file "DSC02035.jpg" written to XMP sidecar.
digikam.metaengine: Loading metadata with "Exiv2" backend from "/tmp/testalbum/DSC02035.jpg"
digikam.dimg: "/tmp/testalbum/DSC02035.jpg" : "JPEG" file identified
digikam.database: Scanning took 12 ms
digikam.database: Finishing took 6 ms
digikam.metaengine: Loading metadata with "Exiv2" backend from "/tmp/testalbum/DSC02035.jpg"
digikam.general: Trying to get thumbnail from "/tmp/testalbum/DSC02035.jpg" ( "image" )
digikam.general: Trying to get thumbnail with Exiv2 for "/tmp/testalbum/DSC02035.jpg"
digikam.general: Trying to get thumbnail with DImg preview for "/tmp/testalbum/DSC02035.jpg"
digikam.general: mimetype =  "JPEG"  ext =  "JPG"
digikam.general: Threads Pool "" will use 4 threads
digikam.general: Action Thread run 1 new jobs
digikam.general: One job is done Digikam::TagsJob(0x55efebf64fa0) time: 132
digikam.general: Finish Main Thread
digikam.general: Threads Pool "" will use 4 threads
digikam.general: Action Thread run 1 new jobs
digikam.general: One job is done Digikam::DatesJob(0x7f51400254b0) time: 406
digikam.general: Finish Main Thread
Comment 5 Maik Qualmann 2026-02-11 20:52:45 UTC
Git commit 799dcfb5893a6754a0aec27be8967c824f24a872 by Maik Qualmann.
Committed on 11/02/2026 at 20:51.
Pushed by mqualmann into branch 'master'.

fix a cache issue in ItemInfo
When we delete an image, it remains in the cache.
If we re-import the same image, it is recognized in
the cache and initially used with the old metadata.

M  +3    -0    core/libs/database/coredb/coredb.cpp
M  +5    -0    core/libs/database/item/containers/iteminfo.cpp
M  +5    -0    core/libs/database/item/containers/iteminfocache.cpp
M  +1    -0    core/libs/database/item/containers/iteminfodata.h

https://invent.kde.org/graphics/digikam/-/commit/799dcfb5893a6754a0aec27be8967c824f24a872
Comment 6 Maik Qualmann 2026-02-13 11:32:57 UTC
I can no longer reproduce the problem. The prerequisite is that rotation is actually performed at the pixel level. Rotation using only the rotation flag is not only partially possible with these sidecar settings (only in the XMP file).

Please post your metadata rotation settings.

Maik
Comment 7 Maik Qualmann 2026-02-14 20:45:19 UTC
Git commit f3b8ca598814add331803a1bc4363b417a06fbce by Maik Qualmann.
Committed on 14/02/2026 at 20:44.
Pushed by mqualmann into branch 'master'.

always write rotation flag to file if the rotation option is enabled
FIXED-IN: 9.0.0

M  +1    -1    NEWS
M  +23   -1    core/libs/fileactionmanager/fileworkeriface.cpp
M  +1    -0    core/libs/video/player/qtmm/mediaplayerview.cpp

https://invent.kde.org/graphics/digikam/-/commit/f3b8ca598814add331803a1bc4363b417a06fbce
Comment 8 Markus S. 2026-02-16 15:12:27 UTC
Thanks, Maik, the bug is fixed now. Verified using digiKam-9.0.0-20260216T110056-Qt6-x86-64.appimage
Comment 9 Maik Qualmann 2026-04-15 19:26:55 UTC
Git commit 133ef5634d218cd1943fb8d11662d6bba82a20ca by Maik Qualmann.
Committed on 15/04/2026 at 19:25.
Pushed by mqualmann into branch 'master'.

change writing rotation flag behavior
Related: bug 518981
FIXED-IN: 9.1.0

M  +1    -1    NEWS
M  +11   -11   core/libs/fileactionmanager/fileworkeriface.cpp

https://invent.kde.org/graphics/digikam/-/commit/133ef5634d218cd1943fb8d11662d6bba82a20ca