diff options
author | Corey Hulen <corey@hulen.com> | 2015-08-02 08:58:33 -0800 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2015-08-02 08:58:33 -0800 |
commit | 41f96636d6a92f622518271f9ea7dd66c8c84e47 (patch) | |
tree | b9462b5385b505a0220a1df47e5efe64fd2d84d0 /api | |
parent | 810c527fcbf5a9b4e32fe94e3ea00e20bddc020a (diff) | |
parent | dad78514234029791ff02c9a0efd2cbacdac5280 (diff) | |
download | chat-41f96636d6a92f622518271f9ea7dd66c8c84e47.tar.gz chat-41f96636d6a92f622518271f9ea7dd66c8c84e47.tar.bz2 chat-41f96636d6a92f622518271f9ea7dd66c8c84e47.zip |
Merge pull request #274 from mattermost/mm-1497
MM-1497 image thumbnails now scale appropriately so there is no whitespace
Diffstat (limited to 'api')
-rw-r--r-- | api/file.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/api/file.go b/api/file.go index 219cf6103..4ec421eb9 100644 --- a/api/file.go +++ b/api/file.go @@ -140,11 +140,18 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch // Create thumbnail go func() { + thumbWidth := float64(utils.Cfg.ImageSettings.ThumbnailWidth) + thumbHeight := float64(utils.Cfg.ImageSettings.ThumbnailHeight) + imgWidth := float64(imgConfig.Width) + imgHeight := float64(imgConfig.Height) + var thumbnail image.Image - if imgConfig.Width > int(utils.Cfg.ImageSettings.ThumbnailWidth) { - thumbnail = resize.Resize(utils.Cfg.ImageSettings.ThumbnailWidth, utils.Cfg.ImageSettings.ThumbnailHeight, img, resize.Lanczos3) - } else { + if imgHeight < thumbHeight && imgWidth < thumbWidth { thumbnail = img + } else if imgHeight/imgWidth < thumbHeight/thumbWidth { + thumbnail = resize.Resize(0, utils.Cfg.ImageSettings.ThumbnailHeight, img, resize.Lanczos3) + } else { + thumbnail = resize.Resize(utils.Cfg.ImageSettings.ThumbnailWidth, 0, img, resize.Lanczos3) } buf := new(bytes.Buffer) |