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> 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<double>(maxWidth) / originalWidth;
double heightRatio = static_cast<double>(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<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);
}
return resizedImages;