[MM-13158] Initial attempt at extracting SVG dimensions (#10332)

* initial attempt at extracting svg dimensions

* rafactor SVG dimensions extraction

* pass SVG parsing errors to calling context

* tweaks to svg parsing placement

- also stopped trying to pre/post process SVG’s as images

* add svg parsing tests

* updates for PR change requests

* code review updates

* correct a conditional typo
Этот коммит содержится в:
Dean Whillier
2019-02-27 14:06:56 -05:00
коммит произвёл GitHub
родитель 4013e77e3e
Коммит df6b8ff768
3 изменённых файлов: 150 добавлений и 0 удалений

Просмотреть файл

@@ -673,6 +673,20 @@ func (t *uploadFileTask) runPlugins() *model.AppError {
}
func (t *uploadFileTask) preprocessImage() *model.AppError {
// If SVG, attempt to extract dimensions and then return
if t.fileinfo.MimeType == "image/svg+xml" {
svgInfo, err := parseSVG(t.newReader())
if err != nil {
mlog.Error("Failed to parse SVG", mlog.Err(err))
}
if svgInfo.Width > 0 && svgInfo.Height > 0 {
t.fileinfo.Width = svgInfo.Width
t.fileinfo.Height = svgInfo.Height
}
t.fileinfo.HasPreviewImage = false
return nil
}
// If we fail to decode, return "as is".
config, _, err := image.DecodeConfig(t.newReader())
if err != nil {
@@ -723,6 +737,11 @@ func (t *uploadFileTask) preprocessImage() *model.AppError {
}
func (t *uploadFileTask) postprocessImage() {
// don't try to process SVG files
if t.fileinfo.MimeType == "image/svg+xml" {
return
}
decoded, typ := t.decoded, t.imageType
if decoded == nil {
var err error