diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-08-14 00:25:57 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-14 00:25:57 +0200 |
commit | 5a491c4f8342a9d4fdde4a1679ec747cd336c687 (patch) | |
tree | aa1323288ad45021e177293f4c0aaf08158fdd98 | |
parent | df3252ca6ee12bafafb5aaed298193142ff93248 (diff) |
Support some more image formats
-rw-r--r-- | ui/commands.go | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/ui/commands.go b/ui/commands.go index 0cbf2b0..6e9d3b7 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -309,26 +309,18 @@ func uploadImage(cmd *Command, filePath string, fileName string) { } fileSize := len(fileData) - imageMetadata, _, err := image.DecodeConfig(bytes.NewReader(fileData)) + imageMetadata, format, err := image.DecodeConfig(bytes.NewReader(fileData)) if err != nil { cmd.Reply("Failed to decode image") return } - var imageType string - // TODO: Detect all types matrix supports - if fileSize >= 4 && fileData[0] == 0xFF && fileData[1] == 0xD8 && fileData[fileSize-2] == 0xFF && fileData[fileSize-1] == 0xD9 { - imageType = "jpeg" - } else if fileSize >= 8 && string(fileData[0:8]) == "\211PNG\r\n\032\n" { - imageType = "png" - } - - if imageType == "" { - cmd.Reply("Only jpeg, png, webm and mp4 files are supported") + if format == "" { + cmd.Reply("Unknown image format for file: %s", filePath) return } - imageMimeType := fmt.Sprintf("image/%s", imageType) + imageMimeType := fmt.Sprintf("image/%s", format) resp, err := cmd.Matrix.Client().UploadBytesWithName(fileData, imageMimeType, fileName) if err != nil { |