@@ -28,38 +28,36 @@ async def logo_func(event):
28
28
font_ = await temp .download_media ("resources/fonts/" )
29
29
elif "pic" in mediainfo (temp .media ):
30
30
bg_ = await temp .download_media ()
31
- if not bg_ :
32
- if event .client ._bot :
33
- SRCH = [
34
- "blur background" ,
35
- "background" ,
36
- "neon lights" ,
37
- "nature" ,
38
- "abstract" ,
39
- "space" ,
40
- "3d render" ,
41
- ]
42
- with rm .get ("search" , helper = True , dispose = True ) as mod :
43
- res = await mod .unsplash (random .choice (SRCH ), limit = 1 )
44
- bg_ , _ = await download_file (res [0 ], "resources/downloads/logo.png" )
45
- newimg = "resources/downloads/unsplash-temp.jpg"
46
- img_ = Image .open (bg_ )
47
- img_ .resize ((5000 , 5000 )).save (newimg )
48
- os .remove (bg_ )
49
- bg_ = newimg
50
- else :
51
- pics = []
52
- async for i in event .client .iter_messages (
53
- "@UltroidLogos" , filter = InputMessagesFilterPhotos
54
- ):
55
- pics .append (i )
56
- id_ = random .choice (pics )
57
- bg_ = await id_ .download_media ()
31
+ SRCH = [
32
+ "background" ,
33
+ "neon" ,
34
+ "anime" ,
35
+ "art" ,
36
+ "bridges" ,
37
+ "streets" ,
38
+ "computer" ,
39
+ "cyberpunk" ,
40
+ "nature" ,
41
+ "abstract" ,
42
+ "exoplanet" ,
43
+ "magic" ,
44
+ "3d render" ,
45
+ ]
46
+ with rm .get ("search" , helper = True , dispose = True ) as mod :
47
+ res = await mod .unsplash (random .choice (SRCH ), limit = 1 )
48
+ bg_ , _ = await download_file (res [0 ], "resources/downloads/logo.png" )
49
+ newimg = "resources/downloads/unsplash-temp.jpg"
50
+ img_ = Image .open (bg_ )
51
+ img_ .resize ((5000 , 5000 )).save (newimg )
52
+ os .remove (bg_ )
53
+ bg_ = newimg
58
54
59
55
if not font_ :
60
56
fpath_ = glob .glob ("resources/fonts/*" )
61
57
if not bool (fpath_ ):
62
- return await xx .edit ("Add fonts in `resourses/fonts/` directory before using this command." )
58
+ return await xx .edit (
59
+ "Add fonts in `resourses/fonts/` directory before using this command."
60
+ )
63
61
font_ = random .choice (fpath_ )
64
62
if len (name ) <= 8 :
65
63
strke = 10
@@ -88,15 +86,23 @@ async def logo_func(event):
88
86
os .remove (bg_ )
89
87
90
88
89
+
90
+
91
+
91
92
class LogoHelper :
93
+ @staticmethod
94
+ def get_text_size (text , image , font ):
95
+ im = Image .new ("RGB" , (image .width , image .height ))
96
+ draw = ImageDraw .Draw (im )
97
+ return draw .textlength (text , font )
98
+
92
99
@staticmethod
93
100
def find_font_size (text , font , image , target_width_ratio ):
94
101
tested_font_size = 100
95
102
tested_font = ImageFont .truetype (font , tested_font_size )
96
- observed_width , observed_height = tested_font . getsize (text )
103
+ observed_width = LogoHelper . get_text_size (text , image , tested_font )
97
104
estimated_font_size = (
98
- tested_font_size / (observed_width /
99
- image .width ) * target_width_ratio
105
+ tested_font_size / (observed_width / image .width ) * target_width_ratio
100
106
)
101
107
return round (estimated_font_size )
102
108
@@ -109,12 +115,19 @@ def make_logo(imgpath, text, funt, **args):
109
115
110
116
img = Image .open (imgpath )
111
117
width , height = img .size
118
+ fct = min (height , width )
119
+ if height != width :
120
+ img = img .crop ((0 , 0 , fct , fct ))
121
+ if img .height < 1000 :
122
+ img = img .resize ((1020 , 1020 ))
123
+ width , height = img .size
112
124
draw = ImageDraw .Draw (img )
113
125
font_size = LogoHelper .find_font_size (text , funt , img , width_ratio )
114
126
font = ImageFont .truetype (funt , font_size )
115
- w , h = font .getsize (text )
127
+ l , t , r , b = font .getbbox (text )
128
+ w , h = r - l , (b - t ) * 1.5
116
129
draw .text (
117
- ((width - w ) / 2 , (height - h ) / 2 ),
130
+ ((width - w ) / 2 , (( height - h ) / 2 ) ),
118
131
text ,
119
132
font = font ,
120
133
fill = fill ,
0 commit comments