summaryrefslogtreecommitdiffstats
path: root/api/file.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-07-29 10:09:11 -0400
committerJoramWilander <jwawilander@gmail.com>2015-07-31 09:36:45 -0400
commita541f09380ab2adbe4d0ba7c80ff72015767bd81 (patch)
treebcf701536501e9deff006607cc8c861de7bc24ce /api/file.go
parentd0865b78b776714139f3a6e39527e00fb05b8ea6 (diff)
downloadchat-a541f09380ab2adbe4d0ba7c80ff72015767bd81.tar.gz
chat-a541f09380ab2adbe4d0ba7c80ff72015767bd81.tar.bz2
chat-a541f09380ab2adbe4d0ba7c80ff72015767bd81.zip
image thumbnails now scale appropriately so there is no whitespace, also generalized some thumbnail loading code
Diffstat (limited to 'api/file.go')
-rw-r--r--api/file.go13
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)