set transparent png background to white

Этот коммит содержится в:
Jack
2015-09-24 08:33:15 -07:00
родитель 8617c6a4a3
Коммит aa6da728ba

Просмотреть файл

@@ -16,6 +16,8 @@ import (
"github.com/rwcarlsen/goexif/exif" "github.com/rwcarlsen/goexif/exif"
_ "golang.org/x/image/bmp" _ "golang.org/x/image/bmp"
"image" "image"
"image/color"
"image/draw"
_ "image/gif" _ "image/gif"
"image/jpeg" "image/jpeg"
"io" "io"
@@ -158,7 +160,7 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch
name := filename[:strings.LastIndex(filename, ".")] name := filename[:strings.LastIndex(filename, ".")]
go func() { go func() {
// Decode image bytes into Image object // 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 { if err != nil {
l4g.Error("Unable to decode image channelId=%v userId=%v filename=%v err=%v", channelId, userId, filename, err) l4g.Error("Unable to decode image channelId=%v userId=%v filename=%v err=%v", channelId, userId, filename, err)
return 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 // Get the image's orientation and ignore any errors since not all images will have orientation data
orientation, _ := getImageOrientation(fileData[i]) 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 { switch orientation {
case UprightMirrored: case UprightMirrored:
img = imaging.FlipH(img) img = imaging.FlipH(img)