From 4f20ebead36876a88391bf033d1de3e4cf0228da Mon Sep 17 00:00:00 2001 From: Wim Date: Thu, 31 Dec 2020 14:48:12 +0100 Subject: Update vendor for next release (#1343) --- .../mattermost-server/v5/model/file_info.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'vendor/github.com/mattermost/mattermost-server/v5/model/file_info.go') 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, -- cgit v1.2.3