1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-09-10 12:03:18 +02:00

avatar: fix image cropping

Take into consideration the vertical margin when cropping the image.

Change-Id: I140c96f54d2c1ae732bd104fb21ad04d66d97e9a
This commit is contained in:
Kateryna Kostiuk 2024-05-29 16:35:18 -04:00 committed by Sébastien Blin
parent 519871e458
commit 89bed2bf85

View file

@ -540,13 +540,20 @@ Utils::getCirclePhoto(const QImage original, int sizePhoto)
Qt::KeepAspectRatioByExpanding,
Qt::SmoothTransformation)
.convertToFormat(QImage::Format_ARGB32_Premultiplied);
int margin = 0;
int marginX = 0;
int marginY = 0;
if (scaledPhoto.width() > sizePhoto) {
margin = (scaledPhoto.width() - sizePhoto) / 2;
marginX = (scaledPhoto.width() - sizePhoto) / 2;
}
if (scaledPhoto.height() > sizePhoto) {
marginY = (scaledPhoto.height() - sizePhoto) / 2;
}
painter.drawEllipse(0, 0, sizePhoto, sizePhoto);
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.drawImage(0, 0, scaledPhoto, margin, 0);
painter.drawImage(0, 0, scaledPhoto, marginX, marginY);
return target;
}