Co-authored-by: New-dev0 <New-dev0@users.noreply.github.com> Co-authored-by: Amit Sharma <buddhhu@users.noreply.github.com> Co-authored-by: TechiError <techierror@users.noreply.github.com> Co-authored-by: Aditya <me@xditya.me> Co-authored-by: Sonya Nikiforova <Sonniki@users.noreply.github.com> Co-authored-by: M̲αραт <Marty2509@users.noreply.github.com> Co-authored-by: Muhamad Risman Aziz <mrismanaziz@users.noreply.github.com> Co-authored-by: Arnab Paryali <Arnabxd@users.noreply.github.com> Co-authored-by: hellboi_atul <hellboi-atul@users.noreply.github.com> Co-authored-by: sppidy <sppidy@users.noreply.github.com>
111 lines
3.3 KiB
Python
111 lines
3.3 KiB
Python
# Ultroid - UserBot
|
|
# Copyright (C) 2021 TeamUltroid
|
|
#
|
|
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
|
# PLease read the GNU Affero General Public License in
|
|
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
|
"""
|
|
✘ Commands Available -
|
|
|
|
• `{i}logo <text>`
|
|
Generate a logo of the given Text
|
|
Or Reply To image , to write ur text on it.
|
|
Or Reply To Font File, To write with that font.
|
|
|
|
"""
|
|
import glob
|
|
import os
|
|
import random
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
from pyUltroid.functions.misc import unsplashsearch
|
|
from telethon.tl.types import InputMessagesFilterPhotos
|
|
|
|
from . import (
|
|
OWNER_ID,
|
|
OWNER_NAME,
|
|
download_file,
|
|
eor,
|
|
get_string,
|
|
mediainfo,
|
|
ultroid_cmd,
|
|
)
|
|
|
|
|
|
@ultroid_cmd(pattern="logo ?(.*)")
|
|
async def logo_gen(event):
|
|
xx = await eor(event, get_string("com_1"))
|
|
name = event.pattern_match.group(1)
|
|
if not name:
|
|
await eor(xx, "`Give a name too!`", time=5)
|
|
bg_, font_ = None, None
|
|
if event.reply_to_msg_id:
|
|
temp = await event.get_reply_message()
|
|
if temp.media:
|
|
if hasattr(temp.media, "document"):
|
|
if "font" in temp.file.mime_type:
|
|
font_ = await temp.download_media()
|
|
elif (".ttf" in temp.file.name) or (".otf" in temp.file.name):
|
|
font_ = await temp.download_media()
|
|
elif "pic" in mediainfo(temp.media):
|
|
bg_ = await temp.download_media()
|
|
if not bg_:
|
|
if event.client._bot:
|
|
SRCH = ["blur background", "background", "neon lights", "wallpaper"]
|
|
res = await unsplashsearch(random.choice(SRCH), limit=1)
|
|
bg_ = await download_file(res[0], "resources/downloads/logo.png")
|
|
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()
|
|
|
|
if not font_:
|
|
fpath_ = glob.glob("resources/fonts/*")
|
|
font_ = random.choice(fpath_)
|
|
if len(name) <= 8:
|
|
fnt_size = 150
|
|
strke = 10
|
|
elif len(name) >= 9:
|
|
fnt_size = 50
|
|
strke = 5
|
|
else:
|
|
fnt_size = 130
|
|
strke = 20
|
|
img = Image.open(bg_)
|
|
draw = ImageDraw.Draw(img)
|
|
font = ImageFont.truetype(font_, fnt_size)
|
|
w, h = draw.textsize(name, font=font)
|
|
h += int(h * 0.21)
|
|
image_width, image_height = img.size
|
|
draw.text(
|
|
((image_width - w) / 2, (image_height - h) / 2),
|
|
name,
|
|
font=font,
|
|
fill=(255, 255, 255),
|
|
)
|
|
x = (image_width - w) / 2
|
|
y = (image_height - h) / 2
|
|
draw.text(
|
|
(x, y), name, font=font, fill="white", stroke_width=strke, stroke_fill="black"
|
|
)
|
|
flnme = "ultd.png"
|
|
img.save(flnme, "png")
|
|
await xx.edit("`Done!`")
|
|
if os.path.exists(flnme):
|
|
await event.client.send_file(
|
|
event.chat_id,
|
|
file=flnme,
|
|
caption=f"Logo by [{OWNER_NAME}](tg://user?id={OWNER_ID})",
|
|
force_document=True,
|
|
)
|
|
os.remove(flnme)
|
|
await xx.delete()
|
|
if os.path.exists(bg_):
|
|
os.remove(bg_)
|
|
if os.path.exists(font_) and not font_.startswith("resources/fonts"):
|
|
os.remove(font_)
|