PLT-6659 Fixed upload thumbnails that weren't properly rotated (#6816)
- Used client-side EXIF data to rotate profile picture thumbnails - Added a small package for correctly translating EXIF orientation into CSS transforms - Instead of displaying the image using FileReader, used URL.createObjectURL because it is faster - For upload thumbnails, the original behavior was scaling the entire original image, without accounting for EXIF rotate. I changed this to use the thumbnail image, which does respect rotation. - The preview image was not available when the upload request returned, because handling the preview image creation was in a goroutine. I used sync.WaitGroup to block until the preview image creation is done.
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
b03b9d7362
Коммит
998b8f70c2
25
app/file.go
25
app/file.go
@@ -480,15 +480,24 @@ func DoUploadFile(teamId string, channelId string, userId string, rawFilename st
|
||||
}
|
||||
|
||||
func HandleImages(previewPathList []string, thumbnailPathList []string, fileData [][]byte) {
|
||||
for i, data := range fileData {
|
||||
go func(i int, data []byte) {
|
||||
img, width, height := prepareImage(fileData[i])
|
||||
if img != nil {
|
||||
go generateThumbnailImage(*img, thumbnailPathList[i], width, height)
|
||||
go generatePreviewImage(*img, previewPathList[i], width)
|
||||
}
|
||||
}(i, data)
|
||||
wg := new(sync.WaitGroup)
|
||||
|
||||
for i := range fileData {
|
||||
img, width, height := prepareImage(fileData[i])
|
||||
if img != nil {
|
||||
wg.Add(2)
|
||||
go func(img *image.Image, path string, width int, height int) {
|
||||
defer wg.Done()
|
||||
generateThumbnailImage(*img, path, width, height)
|
||||
}(img,thumbnailPathList[i], width, height)
|
||||
|
||||
go func(img *image.Image, path string, width int) {
|
||||
defer wg.Done()
|
||||
generatePreviewImage(*img, path, width)
|
||||
}(img, previewPathList[i], width)
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func prepareImage(fileData []byte) (*image.Image, int, int) {
|
||||
|
||||
Ссылка в новой задаче
Block a user