Files
youtube-dl/lib/support/base/image.py

32 lines
885 B
Python
Raw Normal View History

2025-12-25 19:42:32 +09:00
import os
import sys
import traceback
2022-10-02 20:18:05 +09:00
from io import BytesIO
2025-12-25 19:42:32 +09:00
import requests
2022-10-02 20:18:05 +09:00
from . import logger
2025-12-25 19:42:32 +09:00
2022-10-02 20:18:05 +09:00
class SupportImage(object):
@classmethod
def horizontal_to_vertical(cls, url):
try:
from PIL import Image
im = Image.open(requests.get(url, stream=True).raw)
width,height = im.size
new_height = int(width * 1.5)
new_im = Image.new('RGB', (width, new_height))
new_im.paste(im, (0, int((new_height-height)/2)))
img_byte_arr = BytesIO()
new_im.save(img_byte_arr, format='PNG')
img_byte_arr = img_byte_arr.getvalue()
from . import SupportDiscord
return SupportDiscord.discord_proxy_image_bytes(img_byte_arr)
except Exception as e:
2025-12-25 19:42:32 +09:00
logger.error(f"Exception:{str(e)}")
2022-10-02 20:18:05 +09:00
logger.error(traceback.format_exc())