Preserve aspect ratio of tall, skinny images in thumbnails.

This commit is contained in:
Alan De Smet 2019-03-22 22:55:34 -05:00 committed by Stefan Haustein
parent 69f57a4730
commit 6b80bc0717

View file

@ -526,6 +526,7 @@ int main(int argc, char* argv[]) {
int cw = (((maxWidth / 4) - 2 * (columns - 1)) / columns); int cw = (((maxWidth / 4) - 2 * (columns - 1)) / columns);
int tw = cw * 4; int tw = cw * 4;
cimg_library::CImg<unsigned char> image(tw * columns + 2 * 4 * (columns - 1), tw, 1, 3); cimg_library::CImg<unsigned char> image(tw * columns + 2 * 4 * (columns - 1), tw, 1, 3);
size maxThumbSize(tw, tw);
while (index < file_names.size()) { while (index < file_names.size()) {
image.fill(0); image.fill(0);
@ -537,9 +538,9 @@ int main(int argc, char* argv[]) {
cimg_library::CImg<unsigned char> original = load_rgb_CImg(name.c_str()); cimg_library::CImg<unsigned char> original = load_rgb_CImg(name.c_str());
unsigned int cut = name.find_last_of("/"); unsigned int cut = name.find_last_of("/");
sb += cut == std::string::npos ? name : name.substr(cut + 1); sb += cut == std::string::npos ? name : name.substr(cut + 1);
int th = original.height() * tw / original.width(); size newSize = fit_within(maxThumbSize, size(original));
original.resize(tw, th, 1, -100, 5); original.resize(newSize.width, newSize.height, 1, -100, 5);
image.draw_image(count * (tw + 8), (tw - th) / 2, 0, 0, original); image.draw_image(count * (tw + 8), (tw - newSize.height) / 2, 0, 0, original);
count++; count++;
unsigned int sl = count * (cw + 2); unsigned int sl = count * (cw + 2);
sb.resize(sl - 2, ' '); sb.resize(sl - 2, ' ');