fix: logo command

This commit is contained in:
Devesh Pal
2024-05-17 07:58:48 +05:30
parent 4264383e61
commit f81b418c10
5 changed files with 32 additions and 29 deletions

View File

@@ -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/*")

View File

@@ -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,

View File

@@ -1,2 +1,2 @@
__version__ = "2023.02.20"
ultroid_version = "0.8"
ultroid_version = "0.9"

View File

@@ -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

View File

@@ -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