diff options
author | Wim <wim@42.be> | 2020-12-31 14:48:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-31 14:48:12 +0100 |
commit | 4f20ebead36876a88391bf033d1de3e4cf0228da (patch) | |
tree | 70b6fd79c6a5e00c958c29a7bd3926f074e76ba6 /vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go | |
parent | a9f89dbc645aafc68daa9fc8d589f55104b535c7 (diff) | |
download | matterbridge-msglm-4f20ebead36876a88391bf033d1de3e4cf0228da.tar.gz matterbridge-msglm-4f20ebead36876a88391bf033d1de3e4cf0228da.tar.bz2 matterbridge-msglm-4f20ebead36876a88391bf033d1de3e4cf0228da.zip |
Update vendor for next release (#1343)
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go')
-rw-r--r-- | vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go b/vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go index aded5be9..c622b8f2 100644 --- a/vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go +++ b/vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go @@ -4,14 +4,19 @@ package model import ( + "bytes" "encoding/json" "image" "image/gif" + "image/jpeg" "io" "mime" "net/http" "path/filepath" "strings" + + "github.com/disintegration/imaging" + "github.com/mattermost/mattermost-server/v5/mlog" ) const ( @@ -53,6 +58,7 @@ type FileInfo struct { Height int `json:"height,omitempty"` HasPreviewImage bool `json:"has_preview_image,omitempty"` MiniPreview *[]byte `json:"mini_preview"` // declared as *[]byte to avoid postgres/mysql differences in deserialization + Content string `json:"-"` } func (fi *FileInfo) ToJson() string { @@ -151,6 +157,19 @@ func NewInfo(name string) *FileInfo { return info } +func GenerateMiniPreviewImage(img image.Image) *[]byte { + preview := imaging.Resize(img, 16, 16, imaging.Lanczos) + + buf := new(bytes.Buffer) + + if err := jpeg.Encode(buf, preview, &jpeg.Options{Quality: 90}); err != nil { + mlog.Error("Unable to encode image as mini preview jpg", mlog.Err(err)) + return nil + } + data := buf.Bytes() + return &data +} + func GetInfoForBytes(name string, data io.ReadSeeker, size int) (*FileInfo, *AppError) { info := &FileInfo{ Name: name, |