From 646bbceb998047ec6d6479462abbb8152ab97097 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 19 Dec 2020 14:14:33 +0200 Subject: [PATCH] Remove webp conversion --- mautrix_telegram/portal/telegram.py | 8 ++++++++ mautrix_telegram/util/file_transfer.py | 14 +++----------- optional-requirements.txt | 3 --- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/mautrix_telegram/portal/telegram.py b/mautrix_telegram/portal/telegram.py index 104f5065..cf7ea41d 100644 --- a/mautrix_telegram/portal/telegram.py +++ b/mautrix_telegram/portal/telegram.py @@ -229,6 +229,14 @@ class PortalTelegram(BasePortal, ABC): # Elements only support images as stickers, so send animated webm stickers as m.video if attrs.is_sticker and file.mime_type.startswith("image/"): event_type = EventType.STICKER + # Tell clients to render the stickers as 256x256 if they're bigger + if info.width > 256 or info.height > 256: + if info.width > info.height: + info.height = int(info.height / (info.width / 256)) + info.width = 256 + else: + info.width = int(info.width / (info.height / 256)) + info.height = 256 content = MediaMessageEventContent( body=name or "unnamed file", info=info, relates_to=relates_to, external_url=self._get_external_url(evt), diff --git a/mautrix_telegram/util/file_transfer.py b/mautrix_telegram/util/file_transfer.py index da7d3523..c343ab25 100644 --- a/mautrix_telegram/util/file_transfer.py +++ b/mautrix_telegram/util/file_transfer.py @@ -222,9 +222,9 @@ async def _unlocked_transfer_file_to_matrix(client: MautrixTelegramClient, inten image_converted = False # A weird bug in alpine/magic makes it return application/octet-stream for gzips... - is_tgs = (mime_type == "application/gzip" or (mime_type == "application/octet-stream" - and magic.from_buffer(file).startswith( - "gzip"))) + is_tgs = (mime_type == "application/gzip" + or (mime_type == "application/octet-stream" + and magic.from_buffer(file).startswith("gzip"))) if is_sticker and tgs_convert and is_tgs: converted_anim = await convert_tgs_to(file, tgs_convert["target"], **tgs_convert["args"]) @@ -234,14 +234,6 @@ async def _unlocked_transfer_file_to_matrix(client: MautrixTelegramClient, inten image_converted = mime_type != "application/gzip" thumbnail = None - if mime_type == "image/webp": - new_mime_type, file, width, height = convert_image( - file, source_mime="image/webp", target_type="png", - thumbnail_to=(256, 256) if is_sticker else None) - image_converted = new_mime_type != mime_type - mime_type = new_mime_type - thumbnail = None - decryption_info = None upload_mime_type = mime_type if encrypt and encrypt_attachment: diff --git a/optional-requirements.txt b/optional-requirements.txt index c1c114c2..6d76309e 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -7,9 +7,6 @@ cchardet aiodns brotli -#/webp_convert -pillow>=4,<9 - #/qr_login pillow>=4,<9 qrcode>=6,<7