[Avatar] Respect EXIF orientation and decode at target size (#7634)

Read the avatar with setAutoTransform(true) so camera orientation is
applied, and ask QImageReader for a scaled decode at MAX_AVATAR_DIMENSION
instead of decoding a full-resolution photo and scaling it afterwards.

Verification: cockatrice built.

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-10-25 00:11:09 +02:00 • committed by GitHub
parent 66b9338c90
commit 3b07b10b19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -71,7 +71,21 @@ void DlgEditAvatar::actBrowse()
QImageReader imgReader;
imgReader.setDecideFormatFromContent(true);
// Honour the EXIF orientation phone cameras write; otherwise portrait
// photos are shown and stored sideways.
imgReader.setAutoTransform(true);
imgReader.setFileName(fileName);
// Decode straight to the maximum avatar size. Scaling afterwards decodes
// the full-resolution image first, which can be tens of megabytes for a
// modern camera photo.
const QSize sourceSize = imgReader.size();
if (sourceSize.isValid() &&
(sourceSize.width() > MAX_AVATAR_DIMENSION || sourceSize.height() > MAX_AVATAR_DIMENSION)) {
const QSize targetSize = sourceSize.scaled(MAX_AVATAR_DIMENSION, MAX_AVATAR_DIMENSION, Qt::KeepAspectRatio);
imgReader.setScaledSize(targetSize);
}
if (!imgReader.read(&image)) {
qCWarning(DlgEditAvatarLog) << "Avatar image loading failed for file:" << fileName;
imageLabel->setText(tr("Invalid image chosen."));