diff --git a/src/app/utils.cpp b/src/app/utils.cpp index 371974f3f9325aad09f4d3655ef4edcb7a06cf38..fc8324666c5da22e2f44e91ea7cd3a60cffce9b2 100644 --- a/src/app/utils.cpp +++ b/src/app/utils.cpp @@ -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; }