From f81b418c1091ab7d3d73104039e925d8fc5c8aa0 Mon Sep 17 00:00:00 2001 From: Devesh Pal Date: Fri, 17 May 2024 07:58:48 +0530 Subject: [PATCH] fix: logo command --- plugins/logo.py | 37 ++++++++++----------- pyUltroid/fns/tools.py | 17 ++++++---- pyUltroid/version.py | 2 +- requirements.txt | 3 +- resources/startup/optional-requirements.txt | 2 +- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/plugins/logo.py b/plugins/logo.py index 581007a..92531bb 100644 --- a/plugins/logo.py +++ b/plugins/logo.py @@ -48,31 +48,28 @@ async def logo_gen(event): elif "pic" in mediainfo(temp.media): bg_ = await temp.download_media() if not bg_: - if event.client._bot: - SRCH = [ - "blur background", + SRCH = [ "background", - "neon lights", + "neon", + "anime", + "art", + "bridges", + "streets", + "computer", + "cyberpunk", "nature", "abstract", - "space", + "exoplanet", + "magic", "3d render", ] - res = await unsplashsearch(random.choice(SRCH), limit=1) - bg_, _ = await download_file(res[0], "resources/downloads/logo.png") - newimg = "resources/downloads/unsplash-temp.jpg" - img_ = Image.open(bg_) - img_.resize((5000, 5000)).save(newimg) - os.remove(bg_) - bg_ = newimg - else: - pics = [] - async for i in event.client.iter_messages( - "@UltroidLogos", filter=InputMessagesFilterPhotos - ): - pics.append(i) - id_ = random.choice(pics) - bg_ = await id_.download_media() + res = await unsplashsearch(random.choice(SRCH), limit=1) + bg_, _ = await download_file(res[0], "resources/downloads/logo.png") + newimg = "resources/downloads/unsplash-temp.jpg" + img_ = Image.open(bg_) + img_.save(newimg) + os.remove(bg_) + bg_ = newimg if not font_: fpath_ = glob.glob("resources/fonts/*") diff --git a/pyUltroid/fns/tools.py b/pyUltroid/fns/tools.py index 2571314..08be71b 100644 --- a/pyUltroid/fns/tools.py +++ b/pyUltroid/fns/tools.py @@ -297,15 +297,13 @@ class LogoHelper: def get_text_size(text, image, font): im = Image.new("RGB", (image.width, image.height)) draw = ImageDraw.Draw(im) - return draw.textsize(text, font) + return draw.textlength(text, font) @staticmethod def find_font_size(text, font, image, target_width_ratio): tested_font_size = 100 tested_font = ImageFont.truetype(font, tested_font_size) - observed_width, observed_height = LogoHelper.get_text_size( - text, image, tested_font - ) + observed_width = LogoHelper.get_text_size(text, image, tested_font) estimated_font_size = ( tested_font_size / (observed_width / image.width) * target_width_ratio ) @@ -320,12 +318,19 @@ class LogoHelper: img = Image.open(imgpath) width, height = img.size + fct = min(height, width) + if height != width: + img = img.crop((0, 0, fct, fct)) + if img.height < 1000: + img = img.resize((1020, 1020)) + width, height = img.size draw = ImageDraw.Draw(img) font_size = LogoHelper.find_font_size(text, funt, img, width_ratio) font = ImageFont.truetype(funt, font_size) - w, h = draw.textsize(text, font=font) + l, t, r, b = font.getbbox(text) + w, h = r - l, (b - t) * 1.5 draw.text( - ((width - w) / 2, (height - h) / 2), + ((width - w) / 2, ((height - h) / 2)), text, font=font, fill=fill, diff --git a/pyUltroid/version.py b/pyUltroid/version.py index 8c7b646..3bf4e47 100644 --- a/pyUltroid/version.py +++ b/pyUltroid/version.py @@ -1,2 +1,2 @@ __version__ = "2023.02.20" -ultroid_version = "0.8" +ultroid_version = "0.9" diff --git a/requirements.txt b/requirements.txt index 9ca5b38..ac50974 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ # Important Requirements here. -https://github.com/New-dev0/Telethon/archive/platy.zip +telethon +https://github.com/New-dev0/Telethon-Patch/archive/main.zip python-decouple python-dotenv diff --git a/resources/startup/optional-requirements.txt b/resources/startup/optional-requirements.txt index 209127a..721eba8 100644 --- a/resources/startup/optional-requirements.txt +++ b/resources/startup/optional-requirements.txt @@ -17,7 +17,7 @@ lxml numpy>=1.21.2 oauth2client opencv-python-headless -pillow>=7.0.0 +pillow>=9.0.0 profanitydetector psutil pypdf2>=1.26.0