Fixed rescale

This commit is contained in:
Torsten Schulz
2024-04-08 09:39:09 +02:00
parent e05a9429b9
commit b1f4b1a909

View File

@@ -495,13 +495,22 @@ void App::imageUploaded(Wt::WFileUpload *fileWidget, std::shared_ptr<Magick::Blo
std::list<Magick::Image> App::resizeImages(std::list<Magick::Image> &images, int maxWidth, int maxHeight) { std::list<Magick::Image> App::resizeImages(std::list<Magick::Image> &images, int maxWidth, int maxHeight) {
std::list<Magick::Image> resizedImages; std::list<Magick::Image> resizedImages;
for (auto& img : images) { for (auto& img : images) {
Magick::Geometry newSize = img.size(); // Berechne das Verhältnis des Originalbildes
newSize.aspect(true); double originalWidth = img.columns();
if (newSize.width() > maxWidth || newSize.height() > maxHeight) { double originalHeight = img.rows();
newSize.width(maxWidth); double widthRatio = static_cast<double>(maxWidth) / originalWidth;
newSize.height(maxHeight); double heightRatio = static_cast<double>(maxHeight) / originalHeight;
img.resize(newSize); 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<int>(originalWidth * resizeRatio);
int newHeight = static_cast<int>(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); resizedImages.push_back(img);
} }
return resizedImages; return resizedImages;