Repository: getnikola/nikola

Issue:
Thumbnail too small for (very) wide images
### Environment (if reporting a bug)

**Python Version:** Python 3.5

**Nikola Version:** 7.8.5

### Description:

Sometimes I stich images. The thumbnail generated is too small, for instance, in this case:

http://grulicueva.homenet.org/~mdione/nikola-gallery/galleries/Trips/2016/12-24%20-%20Isola%202000/

The thumbnail is 180px × 24px, but it's being shown (in my computer) with this CSS style:

`<div class="image-block" title="" data-toggle="tooltip" data-original-title="12 24t13 05 23" style="width: 1130px; height: 151px; margin-bottom: 5px; margin-left: 0px;"><a href="2016-12-24T13.05.23.jpg" class="image-reference cboxElement"><img src="2016-12-24T13.05.23.thumbnail.jpg" style="max-width: 100%;" height="151" width="1129"></a></div>`

so it's scaling it 6x at least. Maybe this could be fixed with a minimum height x width instead of width alone, but I understand it's a complex problem.


Discussion:
right, yes, this can be special-cased. I'll take a look.

Resolving patch:
diff --git a/nikola/plugins/task/galleries.py b/nikola/plugins/task/galleries.py
--- a/nikola/plugins/task/galleries.py
+++ b/nikola/plugins/task/galleries.py
@@ -479,7 +479,7 @@ def create_target_images(self, img, input_path):
             'targets': [thumb_path],
             'actions': [
                 (self.resize_image,
-                    (img, thumb_path, self.kw['thumbnail_size'], False, self.kw['preserve_exif_data'],
+                    (img, thumb_path, self.kw['thumbnail_size'], True, self.kw['preserve_exif_data'],
                      self.kw['exif_whitelist']))
             ],
             'clean': True,
@@ -495,7 +495,7 @@ def create_target_images(self, img, input_path):
             'targets': [orig_dest_path],
             'actions': [
                 (self.resize_image,
-                    (img, orig_dest_path, self.kw['max_image_size'], False, self.kw['preserve_exif_data'],
+                    (img, orig_dest_path, self.kw['max_image_size'], True, self.kw['preserve_exif_data'],
                      self.kw['exif_whitelist']))
             ],
             'clean': True,
diff --git a/nikola/plugins/task/scale_images.py b/nikola/plugins/task/scale_images.py
--- a/nikola/plugins/task/scale_images.py
+++ b/nikola/plugins/task/scale_images.py
@@ -71,8 +71,8 @@ def process_tree(self, src, dst):
 
     def process_image(self, src, dst, thumb):
         """Resize an image."""
-        self.resize_image(src, dst, self.kw['max_image_size'], False, preserve_exif_data=self.kw['preserve_exif_data'], exif_whitelist=self.kw['exif_whitelist'])
-        self.resize_image(src, thumb, self.kw['image_thumbnail_size'], False, preserve_exif_data=self.kw['preserve_exif_data'], exif_whitelist=self.kw['exif_whitelist'])
+        self.resize_image(src, dst, self.kw['max_image_size'], True, preserve_exif_data=self.kw['preserve_exif_data'], exif_whitelist=self.kw['exif_whitelist'])
+        self.resize_image(src, thumb, self.kw['image_thumbnail_size'], True, preserve_exif_data=self.kw['preserve_exif_data'], exif_whitelist=self.kw['exif_whitelist'])
 
     def gen_tasks(self):
         """Copy static files into the output folder."""


Test patch: