use github.com/disintegration/imaging
Этот коммит содержится в:
64
api/file.go
64
api/file.go
@@ -5,25 +5,21 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"code.google.com/p/graphics-go/graphics"
|
|
||||||
l4g "code.google.com/p/log4go"
|
l4g "code.google.com/p/log4go"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/disintegration/imaging"
|
||||||
"github.com/goamz/goamz/aws"
|
"github.com/goamz/goamz/aws"
|
||||||
"github.com/goamz/goamz/s3"
|
"github.com/goamz/goamz/s3"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/mattermost/platform/model"
|
"github.com/mattermost/platform/model"
|
||||||
"github.com/mattermost/platform/utils"
|
"github.com/mattermost/platform/utils"
|
||||||
"github.com/nfnt/resize"
|
|
||||||
"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"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -174,47 +170,23 @@ 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])
|
||||||
|
|
||||||
// Create a temporary image that will be manipulated and then used to make the thumbnail and preview image
|
|
||||||
var temp *image.RGBA
|
|
||||||
switch orientation {
|
switch orientation {
|
||||||
case Upright, UprightMirrored, UpsideDown, UpsideDownMirrored:
|
case UprightMirrored:
|
||||||
temp = image.NewRGBA(img.Bounds())
|
img = imaging.FlipH(img)
|
||||||
case RotatedCCW, RotatedCCWMirrored, RotatedCW, RotatedCWMirrored:
|
case UpsideDown:
|
||||||
bounds := img.Bounds()
|
img = imaging.Rotate180(img)
|
||||||
temp = image.NewRGBA(image.Rect(bounds.Min.Y, bounds.Min.X, bounds.Max.Y, bounds.Max.X))
|
case UpsideDownMirrored:
|
||||||
|
img = imaging.FlipV(img)
|
||||||
width, height = height, width
|
case RotatedCWMirrored:
|
||||||
|
img = imaging.Transpose(img)
|
||||||
|
case RotatedCCW:
|
||||||
|
img = imaging.Rotate270(img)
|
||||||
|
case RotatedCCWMirrored:
|
||||||
|
img = imaging.Transverse(img)
|
||||||
|
case RotatedCW:
|
||||||
|
img = imaging.Rotate90(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a white background since JPEGs lack transparency
|
|
||||||
draw.Draw(temp, temp.Bounds(), image.NewUniform(color.White), image.Point{}, draw.Src)
|
|
||||||
|
|
||||||
// Copy the original image onto the temporary one while rotating it as necessary
|
|
||||||
switch orientation {
|
|
||||||
case UpsideDown, UpsideDownMirrored:
|
|
||||||
// rotate 180 degrees
|
|
||||||
err := graphics.Rotate(temp, img, &graphics.RotateOptions{Angle: math.Pi})
|
|
||||||
if err != nil {
|
|
||||||
l4g.Error("Unable to rotate image")
|
|
||||||
}
|
|
||||||
case RotatedCW, RotatedCWMirrored:
|
|
||||||
// rotate 90 degrees CCW
|
|
||||||
graphics.Rotate(temp, img, &graphics.RotateOptions{Angle: 3 * math.Pi / 2})
|
|
||||||
if err != nil {
|
|
||||||
l4g.Error("Unable to rotate image")
|
|
||||||
}
|
|
||||||
case RotatedCCW, RotatedCCWMirrored:
|
|
||||||
// rotate 90 degrees CW
|
|
||||||
graphics.Rotate(temp, img, &graphics.RotateOptions{Angle: math.Pi / 2})
|
|
||||||
if err != nil {
|
|
||||||
l4g.Error("Unable to rotate image")
|
|
||||||
}
|
|
||||||
case Upright, UprightMirrored:
|
|
||||||
draw.Draw(temp, temp.Bounds(), img, img.Bounds().Min, draw.Over)
|
|
||||||
}
|
|
||||||
|
|
||||||
img = temp
|
|
||||||
|
|
||||||
// Create thumbnail
|
// Create thumbnail
|
||||||
go func() {
|
go func() {
|
||||||
thumbWidth := float64(utils.Cfg.FileSettings.ThumbnailWidth)
|
thumbWidth := float64(utils.Cfg.FileSettings.ThumbnailWidth)
|
||||||
@@ -226,9 +198,9 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch
|
|||||||
if imgHeight < thumbHeight && imgWidth < thumbWidth {
|
if imgHeight < thumbHeight && imgWidth < thumbWidth {
|
||||||
thumbnail = img
|
thumbnail = img
|
||||||
} else if imgHeight/imgWidth < thumbHeight/thumbWidth {
|
} else if imgHeight/imgWidth < thumbHeight/thumbWidth {
|
||||||
thumbnail = resize.Resize(0, utils.Cfg.FileSettings.ThumbnailHeight, img, resize.Lanczos3)
|
thumbnail = imaging.Resize(img, 0, utils.Cfg.FileSettings.ThumbnailHeight, imaging.Lanczos)
|
||||||
} else {
|
} else {
|
||||||
thumbnail = resize.Resize(utils.Cfg.FileSettings.ThumbnailWidth, 0, img, resize.Lanczos3)
|
thumbnail = imaging.Resize(img, utils.Cfg.FileSettings.ThumbnailWidth, 0, imaging.Lanczos)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
@@ -248,7 +220,7 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch
|
|||||||
go func() {
|
go func() {
|
||||||
var preview image.Image
|
var preview image.Image
|
||||||
if width > int(utils.Cfg.FileSettings.PreviewWidth) {
|
if width > int(utils.Cfg.FileSettings.PreviewWidth) {
|
||||||
preview = resize.Resize(utils.Cfg.FileSettings.PreviewWidth, utils.Cfg.FileSettings.PreviewHeight, img, resize.Lanczos3)
|
preview = imaging.Resize(img, utils.Cfg.FileSettings.PreviewWidth, utils.Cfg.FileSettings.PreviewHeight, imaging.Lanczos)
|
||||||
} else {
|
} else {
|
||||||
preview = img
|
preview = img
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ import (
|
|||||||
l4g "code.google.com/p/log4go"
|
l4g "code.google.com/p/log4go"
|
||||||
b64 "encoding/base64"
|
b64 "encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/disintegration/imaging"
|
||||||
"github.com/golang/freetype"
|
"github.com/golang/freetype"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/mattermost/platform/model"
|
"github.com/mattermost/platform/model"
|
||||||
"github.com/mattermost/platform/store"
|
"github.com/mattermost/platform/store"
|
||||||
"github.com/mattermost/platform/utils"
|
"github.com/mattermost/platform/utils"
|
||||||
"github.com/mssola/user_agent"
|
"github.com/mssola/user_agent"
|
||||||
"github.com/nfnt/resize"
|
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
@@ -775,7 +775,7 @@ func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scale profile image
|
// Scale profile image
|
||||||
img = resize.Resize(utils.Cfg.FileSettings.ProfileWidth, utils.Cfg.FileSettings.ProfileHeight, img, resize.Lanczos3)
|
img = imaging.Resize(img, utils.Cfg.FileSettings.ProfileWidth, utils.Cfg.FileSettings.ProfileHeight, imaging.Lanczos)
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
err = png.Encode(buf, img)
|
err = png.Encode(buf, img)
|
||||||
|
|||||||
@@ -63,12 +63,12 @@ type FileSettings struct {
|
|||||||
Directory string
|
Directory string
|
||||||
EnablePublicLink bool
|
EnablePublicLink bool
|
||||||
PublicLinkSalt string
|
PublicLinkSalt string
|
||||||
ThumbnailWidth uint
|
ThumbnailWidth int
|
||||||
ThumbnailHeight uint
|
ThumbnailHeight int
|
||||||
PreviewWidth uint
|
PreviewWidth int
|
||||||
PreviewHeight uint
|
PreviewHeight int
|
||||||
ProfileWidth uint
|
ProfileWidth int
|
||||||
ProfileHeight uint
|
ProfileHeight int
|
||||||
InitialFont string
|
InitialFont string
|
||||||
AmazonS3AccessKeyId string
|
AmazonS3AccessKeyId string
|
||||||
AmazonS3SecretAccessKey string
|
AmazonS3SecretAccessKey string
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user