Added parameter in config for selecting convert type
This commit is contained in:
@@ -161,7 +161,8 @@ TypeThumbnail = Optional[Union[TypeLocation, TypePhotoSize]]
|
||||
|
||||
async def transfer_file_to_matrix(client: MautrixTelegramClient, intent: IntentAPI,
|
||||
location: TypeLocation, thumbnail: TypeThumbnail = None,
|
||||
is_sticker: bool = False) -> Optional[DBTelegramFile]:
|
||||
is_sticker: bool = False, tgs_convert_type: str = "image") \
|
||||
-> Optional[DBTelegramFile]:
|
||||
location_id = _location_to_id(location)
|
||||
if not location_id:
|
||||
return None
|
||||
@@ -177,12 +178,13 @@ async def transfer_file_to_matrix(client: MautrixTelegramClient, intent: IntentA
|
||||
transfer_locks[location_id] = lock
|
||||
async with lock:
|
||||
return await _unlocked_transfer_file_to_matrix(client, intent, location_id, location,
|
||||
thumbnail, is_sticker)
|
||||
thumbnail, is_sticker, tgs_convert_type)
|
||||
|
||||
|
||||
async def _unlocked_transfer_file_to_matrix(client: MautrixTelegramClient, intent: IntentAPI,
|
||||
loc_id: str, location: TypeLocation,
|
||||
thumbnail: TypeThumbnail, is_sticker: bool
|
||||
thumbnail: TypeThumbnail, is_sticker: bool,
|
||||
tgs_convert_type: str
|
||||
) -> Optional[DBTelegramFile]:
|
||||
db_file = DBTelegramFile.get(loc_id)
|
||||
if db_file:
|
||||
@@ -201,7 +203,7 @@ async def _unlocked_transfer_file_to_matrix(client: MautrixTelegramClient, inten
|
||||
|
||||
image_converted = False
|
||||
if mime_type == "application/gzip" and is_sticker:
|
||||
mime_type, file, width, height, thumbnail = convert_tgs(file, "image", 256, 256)
|
||||
mime_type, file, width, height, thumbnail = convert_tgs(file, tgs_convert_type, 256, 256)
|
||||
image_converted = width is not None
|
||||
|
||||
if mime_type == "image/webp":
|
||||
|
||||
@@ -20,7 +20,7 @@ try:
|
||||
def _tgs_to_png(animation: Animation, width: int = None,
|
||||
height: int = None, frame: int = None) -> Tuple[bytes, Optional[bytes]]:
|
||||
if not frame:
|
||||
frame = int(animation.out_point * 0.3)
|
||||
frame = int(animation.out_point * 0.9)
|
||||
if not (width and height):
|
||||
width = animation.width
|
||||
height = animation.height
|
||||
@@ -82,13 +82,9 @@ try:
|
||||
import numpy
|
||||
import tempfile
|
||||
import os
|
||||
from PIL import Image
|
||||
|
||||
def _tgs_to_video(animation: Animation, width: int = None, height: int = None) \
|
||||
-> Tuple[bytes, Optional[bytes]]:
|
||||
"""
|
||||
FIXME: copy-pasted from tgs.exporters.video, because it's method don't resize images
|
||||
"""
|
||||
start = int(animation.in_point)
|
||||
end = int(animation.out_point)
|
||||
with tempfile.NamedTemporaryFile(mode="r+b", suffix=".mp4") as tmp:
|
||||
|
||||
Reference in New Issue
Block a user