From b1f4b1a909653ba7d753f219cc2fc6b9d827118b Mon Sep 17 00:00:00 2001 From: Torsten Schulz Date: Mon, 8 Apr 2024 09:39:09 +0200 Subject: [PATCH] Fixed rescale --- src/app.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index bd1249c..f1a0902 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -495,13 +495,22 @@ void App::imageUploaded(Wt::WFileUpload *fileWidget, std::shared_ptr App::resizeImages(std::list &images, int maxWidth, int maxHeight) { std::list resizedImages; for (auto& img : images) { - Magick::Geometry newSize = img.size(); - newSize.aspect(true); - if (newSize.width() > maxWidth || newSize.height() > maxHeight) { - newSize.width(maxWidth); - newSize.height(maxHeight); - img.resize(newSize); + // Berechne das Verhältnis des Originalbildes + double originalWidth = img.columns(); + double originalHeight = img.rows(); + double widthRatio = static_cast(maxWidth) / originalWidth; + double heightRatio = static_cast(maxHeight) / originalHeight; + double resizeRatio = std::min(widthRatio, heightRatio); // Nehme das kleinere Verhältnis, um innerhalb der Grenzen zu bleiben + + // Berechne die neuen Dimensionen, um die Proportionen beizubehalten + int newWidth = static_cast(originalWidth * resizeRatio); + int newHeight = static_cast(originalHeight * resizeRatio); + + // Wende die neue Größe an, wenn eine Verkleinerung erforderlich ist + if (resizeRatio < 1) { + img.resize(Magick::Geometry(newWidth, newHeight)); } + resizedImages.push_back(img); } return resizedImages;