From 5a491c4f8342a9d4fdde4a1679ec747cd336c687 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 14 Aug 2020 00:25:57 +0200 Subject: Support some more image formats --- ui/commands.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'ui') 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 { -- cgit v1.2.3