From 6b80bc07172aa29fb0cd4f9ccec257aeca6290ae Mon Sep 17 00:00:00 2001 From: Alan De Smet Date: Fri, 22 Mar 2019 22:55:34 -0500 Subject: [PATCH] Preserve aspect ratio of tall, skinny images in thumbnails. --- src/main/cpp/tiv.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/cpp/tiv.cpp b/src/main/cpp/tiv.cpp index db3fb3f..c967f7d 100644 --- a/src/main/cpp/tiv.cpp +++ b/src/main/cpp/tiv.cpp @@ -526,6 +526,7 @@ int main(int argc, char* argv[]) { int cw = (((maxWidth / 4) - 2 * (columns - 1)) / columns); int tw = cw * 4; cimg_library::CImg image(tw * columns + 2 * 4 * (columns - 1), tw, 1, 3); + size maxThumbSize(tw, tw); while (index < file_names.size()) { image.fill(0); @@ -537,9 +538,9 @@ int main(int argc, char* argv[]) { cimg_library::CImg original = load_rgb_CImg(name.c_str()); unsigned int cut = name.find_last_of("/"); sb += cut == std::string::npos ? name : name.substr(cut + 1); - int th = original.height() * tw / original.width(); - original.resize(tw, th, 1, -100, 5); - image.draw_image(count * (tw + 8), (tw - th) / 2, 0, 0, original); + size newSize = fit_within(maxThumbSize, size(original)); + original.resize(newSize.width, newSize.height, 1, -100, 5); + image.draw_image(count * (tw + 8), (tw - newSize.height) / 2, 0, 0, original); count++; unsigned int sl = count * (cw + 2); sb.resize(sl - 2, ' ');