From ed3f586174b02b2d343e4ed6ec1799f170508d05 Mon Sep 17 00:00:00 2001 From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> Date: Mon, 20 Sep 2021 17:42:56 -0400 Subject: [PATCH] profile-send: center crop profile pic before scaling a compressing Change-Id: I07633e7e1d6b689af30b38648d6c2d354cf2c029 --- src/authority/storagehelper.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/authority/storagehelper.cpp b/src/authority/storagehelper.cpp index 3660d5f3..409ec176 100644 --- a/src/authority/storagehelper.cpp +++ b/src/authority/storagehelper.cpp @@ -159,7 +159,10 @@ compressedAvatar(const QString& image) QByteArray bArray; QBuffer buffer(&bArray); buffer.open(QIODevice::WriteOnly); - qimage.scaled({128, 128}).save(&buffer, "JPEG", 90); + + auto size = qMin(qimage.width(), qimage.height()); + auto rect = QRect((qimage.width() - size) / 2, (qimage.height() - size) / 2, size, size); + qimage.copy(rect).scaled({size, size}, Qt::KeepAspectRatio).save(&buffer, "JPEG", 90); auto b64Img = bArray.toBase64().trimmed(); return QString::fromLocal8Bit(b64Img.constData(), b64Img.length()); } -- GitLab