summaryrefslogtreecommitdiffstats
path: root/api/file.go
diff options
context:
space:
mode:
authorJack <jackdeng@gmail.com>2015-09-24 08:33:15 -0700
committerJack <jackdeng@gmail.com>2015-09-24 08:33:15 -0700
commitaa6da728baf2f5642293d8b56ebc1ff4e8682bce (patch)
tree3573ae49df669fb25443f33ec5ac8c13d4bacec7 /api/file.go
parent8617c6a4a345b047d7a48a34644ff157ef1ba1ec (diff)
downloadchat-aa6da728baf2f5642293d8b56ebc1ff4e8682bce.tar.gz
chat-aa6da728baf2f5642293d8b56ebc1ff4e8682bce.tar.bz2
chat-aa6da728baf2f5642293d8b56ebc1ff4e8682bce.zip
set transparent png background to white
Diffstat (limited to 'api/file.go')
-rw-r--r--api/file.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/api/file.go b/api/file.go
index aa32ea8f4..3606e406e 100644
--- a/api/file.go
+++ b/api/file.go
@@ -16,6 +16,8 @@ import (
"github.com/rwcarlsen/goexif/exif"
_ "golang.org/x/image/bmp"
"image"
+ "image/color"
+ "image/draw"
_ "image/gif"
"image/jpeg"
"io"
@@ -158,7 +160,7 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch
name := filename[:strings.LastIndex(filename, ".")]
go func() {
// Decode image bytes into Image object
- img, _, err := image.Decode(bytes.NewReader(fileData[i]))
+ img, imgType, err := image.Decode(bytes.NewReader(fileData[i]))
if err != nil {
l4g.Error("Unable to decode image channelId=%v userId=%v filename=%v err=%v", channelId, userId, filename, err)
return
@@ -170,6 +172,13 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch
// Get the image's orientation and ignore any errors since not all images will have orientation data
orientation, _ := getImageOrientation(fileData[i])
+ if imgType == "png" {
+ dst := image.NewRGBA(img.Bounds())
+ draw.Draw(dst, dst.Bounds(), image.NewUniform(color.White), image.Point{}, draw.Src)
+ draw.Draw(dst, dst.Bounds(), img, img.Bounds().Min, draw.Over)
+ img = dst
+ }
+
switch orientation {
case UprightMirrored:
img = imaging.FlipH(img)