@@ -23,6 +23,9 @@ class ImpactCommand(commands.Cog):
2323 usage = "`/impact <изображение> <текст> <позиция>`" ,
2424 help = "### Пример:\n `/impact image.png пей горн Низ`"
2525 )
26+ @app_commands .describe (
27+ text = "Текст (до 500 символов)"
28+ )
2629
2730 async def impact (
2831 self ,
@@ -31,6 +34,8 @@ async def impact(
3134 text : str ,
3235 position : str = "down"
3336 ):
37+ text = text [:500 ]
38+
3439 if not image .content_type or "image" not in image .content_type :
3540 raise Exception ("Not image" )
3641 await ctx .defer ()
@@ -67,43 +72,30 @@ async def impact_error(self, ctx, error):
6772
6873def impact (image : Image .Image , text : str , position : str ):
6974 font = "assets/memes/impact.ttf"
70- size = int (image .width / 10 )
75+ size = int (((( image .width + image . height ) / 2 ) / 10 ) / max ( 1 , ( len ( text ) / 25 ) * 0.5 ) )
7176 color = (255 , 255 , 255 )
7277 width = image .size [0 ]
7378 height = image .size [1 ]
79+ padding = int (height / 12 )
80+ text_width = width - padding * 2
7481
7582 image = image .convert (mode = "RGBA" )
7683
7784 # Calculate required heights first
7885 impact_text = ImageText (image , anchor = "ma" )
79- padding = int (height / 12 )
80-
81- # if (taken_space:=impact_text.get_height((int(width/2), 0), text, width, font, size)) > (free_space:=image.height - padding*2):
82- # size = (size / taken_space) * free_space
83- while impact_text .get_height (
84- (int (width / 2 ), 0 ), text , width , font , size , stroke_width = int (size / 16 ), stroke_fill = (0 , 0 , 0 , 255 )
85- ) > image .height / 3 and size > 11 :
86- size -= 10
8786
8887 if position == "down" :
8988 text_height = impact_text .get_height (
90- (int (width / 2 ), 0 ),
91- text ,
92- width ,
93- font ,
94- size ,
89+ (int (width / 2 ), 0 ), text ,
90+ text_width , font , size ,
9591 stroke_width = int (size / 16 ),
9692 stroke_fill = (0 , 0 , 0 , 255 )
9793 )
9894 padding = height - padding - text_height
9995
10096 impact_text .write_text_box (
101- (int (width / 2 ), padding ),
102- text ,
103- width ,
104- font ,
105- size ,
106- color ,
97+ (int (width / 2 ), padding ), text ,
98+ text_width , font , size , color ,
10799 stroke_width = int (size / 16 ),
108100 stroke_fill = (0 , 0 , 0 , 255 )
109101 )
0 commit comments