77#
88# Based code + improve from AdekMaulana and aidilaryanto
99
10- import textwrap
1110import asyncio
1211import os
1312import random
1413import re
14+ import textwrap
1515from asyncio .exceptions import TimeoutError
1616
1717from glitch_this import ImageGlitcher
18- from PIL import Image , ImageDraw , ImageEnhance , ImageFont , ImageOps
18+ from PIL import Image , ImageDraw , ImageFont
1919from telethon import events , functions , types
2020from telethon .errors .rpcerrorlist import YouBlockedUserError
21- from telethon .tl .types import DocumentAttributeFilename
2221
2322from userbot import CMD_HELP , TEMP_DOWNLOAD_DIRECTORY , bot
2423from userbot .events import register
@@ -93,20 +92,20 @@ async def glitch(event):
9392 )
9493 await event .edit ("`Uploading Glitched Media...`" )
9594 nosave = await event .client .send_file (
96- event .chat_id , Glitched , force_document = False , reply_to = event .reply_to_msg_id
97- )
95+ event .chat_id , Glitched , force_document = False , reply_to = event .reply_to_msg_id
96+ )
9897 await event .delete ()
9998 os .remove (Glitched )
10099 await bot (
101- functions .messages .SaveGifRequest (
102- id = types .InputDocument (
103- id = nosave .media .document .id ,
104- access_hash = nosave .media .document .access_hash ,
105- file_reference = nosave .media .document .file_reference ,
106- ),
107- unsave = True ,
108- )
100+ functions .messages .SaveGifRequest (
101+ id = types .InputDocument (
102+ id = nosave .media .document .id ,
103+ access_hash = nosave .media .document .access_hash ,
104+ file_reference = nosave .media .document .file_reference ,
105+ ),
106+ unsave = True ,
109107 )
108+ )
110109 os .remove (glitch_file )
111110
112111
@@ -137,14 +136,16 @@ async def mim(event):
137136 if event .reply_to_msg_id :
138137 file_name = "meme.jpg"
139138 to_download_directory = TEMP_DOWNLOAD_DIRECTORY
140- downloaded_file_name = os .path .join (
141- to_download_directory , file_name )
139+ downloaded_file_name = os .path .join (to_download_directory , file_name )
142140 downloaded_file_name = await bot .download_media (
143- reply_message , downloaded_file_name ,
141+ reply_message ,
142+ downloaded_file_name ,
144143 )
145144 dls_loc = downloaded_file_name
146145 webp_file = await draw_meme_text (dls_loc , text )
147- await event .client .send_file (event .chat_id , webp_file , reply_to = event .reply_to_msg_id )
146+ await event .client .send_file (
147+ event .chat_id , webp_file , reply_to = event .reply_to_msg_id
148+ )
148149 await event .delete ()
149150 os .remove (webp_file )
150151 os .remove (dls_loc )
@@ -155,60 +156,101 @@ async def draw_meme_text(image_path, text):
155156 os .remove (image_path )
156157 i_width , i_height = img .size
157158 m_font = ImageFont .truetype (
158- "resources/MutantAcademyStyle.ttf" , int ((70 / 640 ) * i_width ))
159+ "resources/MutantAcademyStyle.ttf" , int ((70 / 640 ) * i_width )
160+ )
159161 if ";" in text :
160162 upper_text , lower_text = text .split (";" )
161163 else :
162164 upper_text = text
163- lower_text = ''
165+ lower_text = ""
164166 draw = ImageDraw .Draw (img )
165167 current_h , pad = 10 , 5
166168 if upper_text :
167169 for u_text in textwrap .wrap (upper_text , width = 15 ):
168170 u_width , u_height = draw .textsize (u_text , font = m_font )
169171
170- draw .text (xy = (((i_width - u_width ) / 2 ) - 1 , int ((current_h / 640 )
171- * i_width )), text = u_text , font = m_font , fill = (0 , 0 , 0 ))
172- draw .text (xy = (((i_width - u_width ) / 2 ) + 1 , int ((current_h / 640 )
173- * i_width )), text = u_text , font = m_font , fill = (0 , 0 , 0 ))
174- draw .text (xy = ((i_width - u_width ) / 2 ,
175- int (((current_h / 640 ) * i_width )) - 1 ),
176- text = u_text ,
177- font = m_font ,
178- fill = (0 ,
179- 0 ,
180- 0 ))
181- draw .text (xy = (((i_width - u_width ) / 2 ),
182- int (((current_h / 640 ) * i_width )) + 1 ),
183- text = u_text ,
184- font = m_font ,
185- fill = (0 ,
186- 0 ,
187- 0 ))
188-
189- draw .text (xy = ((i_width - u_width ) / 2 , int ((current_h / 640 )
190- * i_width )), text = u_text , font = m_font , fill = (255 , 255 , 255 ))
172+ draw .text (
173+ xy = (((i_width - u_width ) / 2 ) - 1 , int ((current_h / 640 ) * i_width )),
174+ text = u_text ,
175+ font = m_font ,
176+ fill = (0 , 0 , 0 ),
177+ )
178+ draw .text (
179+ xy = (((i_width - u_width ) / 2 ) + 1 , int ((current_h / 640 ) * i_width )),
180+ text = u_text ,
181+ font = m_font ,
182+ fill = (0 , 0 , 0 ),
183+ )
184+ draw .text (
185+ xy = ((i_width - u_width ) / 2 , int (((current_h / 640 ) * i_width )) - 1 ),
186+ text = u_text ,
187+ font = m_font ,
188+ fill = (0 , 0 , 0 ),
189+ )
190+ draw .text (
191+ xy = (((i_width - u_width ) / 2 ), int (((current_h / 640 ) * i_width )) + 1 ),
192+ text = u_text ,
193+ font = m_font ,
194+ fill = (0 , 0 , 0 ),
195+ )
196+
197+ draw .text (
198+ xy = ((i_width - u_width ) / 2 , int ((current_h / 640 ) * i_width )),
199+ text = u_text ,
200+ font = m_font ,
201+ fill = (255 , 255 , 255 ),
202+ )
191203 current_h += u_height + pad
192204 if lower_text :
193205 for l_text in textwrap .wrap (lower_text , width = 15 ):
194206 u_width , u_height = draw .textsize (l_text , font = m_font )
195207
196208 draw .text (
197- xy = (((i_width - u_width ) / 2 ) - 1 , i_height - u_height - int ((20 / 640 ) * i_width )),
198- text = l_text , font = m_font , fill = (0 , 0 , 0 ))
209+ xy = (
210+ ((i_width - u_width ) / 2 ) - 1 ,
211+ i_height - u_height - int ((20 / 640 ) * i_width ),
212+ ),
213+ text = l_text ,
214+ font = m_font ,
215+ fill = (0 , 0 , 0 ),
216+ )
199217 draw .text (
200- xy = (((i_width - u_width ) / 2 ) + 1 , i_height - u_height - int ((20 / 640 ) * i_width )),
201- text = l_text , font = m_font , fill = (0 , 0 , 0 ))
218+ xy = (
219+ ((i_width - u_width ) / 2 ) + 1 ,
220+ i_height - u_height - int ((20 / 640 ) * i_width ),
221+ ),
222+ text = l_text ,
223+ font = m_font ,
224+ fill = (0 , 0 , 0 ),
225+ )
202226 draw .text (
203- xy = ((i_width - u_width ) / 2 , (i_height - u_height - int ((20 / 640 ) * i_width )) - 1 ),
204- text = l_text , font = m_font , fill = (0 , 0 , 0 ))
227+ xy = (
228+ (i_width - u_width ) / 2 ,
229+ (i_height - u_height - int ((20 / 640 ) * i_width )) - 1 ,
230+ ),
231+ text = l_text ,
232+ font = m_font ,
233+ fill = (0 , 0 , 0 ),
234+ )
205235 draw .text (
206- xy = ((i_width - u_width ) / 2 , (i_height - u_height - int ((20 / 640 ) * i_width )) + 1 ),
207- text = l_text , font = m_font , fill = (0 , 0 , 0 ))
236+ xy = (
237+ (i_width - u_width ) / 2 ,
238+ (i_height - u_height - int ((20 / 640 ) * i_width )) + 1 ,
239+ ),
240+ text = l_text ,
241+ font = m_font ,
242+ fill = (0 , 0 , 0 ),
243+ )
208244
209245 draw .text (
210- xy = ((i_width - u_width ) / 2 , i_height - u_height - int ((20 / 640 ) * i_width )),
211- text = l_text , font = m_font , fill = (255 , 255 , 255 ))
246+ xy = (
247+ (i_width - u_width ) / 2 ,
248+ i_height - u_height - int ((20 / 640 ) * i_width ),
249+ ),
250+ text = l_text ,
251+ font = m_font ,
252+ fill = (255 , 255 , 255 ),
253+ )
212254 current_h += u_height + pad
213255
214256 image_name = "memify.webp"
0 commit comments