From 007ee38b042bb6d9e424428b031818ce51f3e242 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 4 Apr 2021 00:15:08 +0200 Subject: [PATCH] Fix exif rotation in unencrypted rooms --- src/MxcImageProvider.cpp | 8 +++++--- src/Utils.cpp | 7 +++++++ src/Utils.h | 4 ++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/MxcImageProvider.cpp b/src/MxcImageProvider.cpp index a20657c8..ab6540a4 100644 --- a/src/MxcImageProvider.cpp +++ b/src/MxcImageProvider.cpp @@ -69,7 +69,7 @@ MxcImageProvider::download(const QString &id, QDir().mkpath(fileInfo.absolutePath()); if (fileInfo.exists()) { - QImage image(fileInfo.absoluteFilePath()); + QImage image = utils::readImageFromFile(fileInfo.absoluteFilePath()); if (!image.isNull()) { image = image.scaled( requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); @@ -143,7 +143,8 @@ MxcImageProvider::download(const QString &id, return; } } else { - QImage image(fileInfo.absoluteFilePath()); + QImage image = + utils::readImageFromFile(fileInfo.absoluteFilePath()); if (!image.isNull()) { then(id, requestedSize, @@ -190,7 +191,8 @@ MxcImageProvider::download(const QString &id, return; } - QImage image(fileInfo.absoluteFilePath()); + QImage image = + utils::readImageFromFile(fileInfo.absoluteFilePath()); image.setText("original filename", QString::fromStdString(originalFilename)); image.setText("mxc url", "mxc://" + id); diff --git a/src/Utils.cpp b/src/Utils.cpp index bf9a8449..ca2d3adc 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -802,6 +802,13 @@ utils::restoreCombobox(QComboBox *combo, const QString &value) } } +QImage +utils::readImageFromFile(const QString &filename) +{ + QImageReader reader(filename); + reader.setAutoTransform(true); + return reader.read(); +} QImage utils::readImage(const QByteArray &data) { diff --git a/src/Utils.h b/src/Utils.h index 37c1baba..7a9eb777 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -310,6 +310,10 @@ centerWidget(QWidget *widget, QWidget *parent); void restoreCombobox(QComboBox *combo, const QString &value); +//! Read image respecting exif orientation +QImage +readImageFromFile(const QString &filename); + //! Read image respecting exif orientation QImage readImage(const QByteArray &data);