MM-49395: Increase compression for previews and emojis (#21985)
We also reduce the max size of uploaded emojis to 512KiB. https://mattermost.atlassian.net/browse/MM-49395 ```release-note Max size of uploaded emojis is now reduced to 512KiB to reduce image download bandwidth. ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1078292ac6
Коммит
a83170e753
@@ -14,7 +14,6 @@ import (
|
||||
"image/draw"
|
||||
"image/gif"
|
||||
_ "image/jpeg"
|
||||
"image/png"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
@@ -31,7 +30,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MaxEmojiFileSize = 1 << 20 // 1 MB
|
||||
MaxEmojiFileSize = 1 << 19 // 512 KiB
|
||||
MaxEmojiWidth = 128
|
||||
MaxEmojiHeight = 128
|
||||
MaxEmojiOriginalWidth = 1028
|
||||
@@ -155,8 +154,8 @@ func (a *App) UploadEmojiImage(c request.CTX, id string, imageData *multipart.Fi
|
||||
return model.NewAppError("uploadEmojiImage", "api.emoji.upload.large_image.decode_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
resized_image := resizeEmoji(img, config.Width, config.Height)
|
||||
if err := png.Encode(newbuf, resized_image); err != nil {
|
||||
resizedImg := resizeEmoji(img, config.Width, config.Height)
|
||||
if err := a.ch.imgEncoder.EncodePNG(newbuf, resizedImg); err != nil {
|
||||
return model.NewAppError("uploadEmojiImage", "api.emoji.upload.large_image.encode_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
buf = newbuf
|
||||
|
||||
@@ -45,7 +45,9 @@ func NewEncoder(opts EncoderOptions) (*Encoder, error) {
|
||||
e.sem = make(chan struct{}, opts.ConcurrencyLevel)
|
||||
}
|
||||
e.opts = opts
|
||||
e.pngEncoder = &png.Encoder{}
|
||||
e.pngEncoder = &png.Encoder{
|
||||
CompressionLevel: png.BestCompression,
|
||||
}
|
||||
return &e, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ func TestAdjustProfileImage(t *testing.T) {
|
||||
assert.True(t, adjusted.Len() > 0)
|
||||
assert.NotEqual(t, testjpg, adjusted)
|
||||
|
||||
// default image should require adjustment
|
||||
// default image should not require adjustment
|
||||
user := th.BasicUser
|
||||
image, err := th.App.GetDefaultProfileImage(user)
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -160,7 +160,10 @@ func createProfileImage(username string, userID string, initialFont string) ([]b
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
if imgErr := png.Encode(buf, dstImg); imgErr != nil {
|
||||
enc := png.Encoder{
|
||||
CompressionLevel: png.BestCompression,
|
||||
}
|
||||
if imgErr := enc.Encode(buf, dstImg); imgErr != nil {
|
||||
return nil, ImageEncodingError
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user