diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_edit_avatar.cpp b/cockatrice/src/interface/widgets/dialogs/dlg_edit_avatar.cpp index 520ece007..7f0141bd5 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_edit_avatar.cpp +++ b/cockatrice/src/interface/widgets/dialogs/dlg_edit_avatar.cpp @@ -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."));