Skip to content

Commit cc7c243

Browse files
committed
MEGA emojis compability
1 parent 33b9cec commit cc7c243

File tree

11 files changed

+85
-36
lines changed

11 files changed

+85
-36
lines changed

assets/memes/arial.ttf

1.02 MB
Binary file not shown.

assets/memes/impact.ttf

1.39 MB
Binary file not shown.

assets/memes/noto_bold.ttf

1.41 MB
Binary file not shown.

assets/memes/test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# from PIL import Image, ImageDraw, ImageFont
2+
3+
# # Load a color emoji font
4+
# font = ImageFont.truetype("noto_bold.ttf", size=60, layout_engine=ImageFont.Layout.BASIC)
5+
6+
# # Create image
7+
# img = Image.new("RGBA", (400, 150), (30, 30, 30))
8+
# draw = ImageDraw.Draw(img)
9+
10+
# # Draw colored emoji
11+
# draw.text((20, 20), "Hello 😄🌍👍", font=font, fill=(255, 255, 255), embedded_color=True)
12+
13+
# # Save output
14+
# img.show()
15+
from PIL import Image
16+
import aggdraw
17+
18+
# Создаем холст
19+
width, height = 400, 100
20+
image = Image.new("RGBA", (width, height), (255, 255, 255, 0)) # прозрачный фон
21+
22+
# Создаем рисовальщик aggdraw
23+
draw = aggdraw.Draw(image)
24+
25+
# Загружаем шрифт (путь к ttf и размер)
26+
font_path = r"C:\Users\bth123\_coding\antbot\assets\memes\noto_bold.ttf"
27+
font_path = "C:/Windows/Fonts/arial.ttf" # для Windows
28+
29+
font_size = 48
30+
font = aggdraw.Font("black", font_path, font_size)
31+
32+
# Пишем текст в центре холста
33+
text = "Hello 😊 Emojis!"
34+
text_position = (10, 10)
35+
draw.text(text_position, text, font)
36+
37+
# Финализируем рисунок
38+
draw.flush()
39+
40+
# Сохраняем результат
41+
image.show()

assets/memes/times.ttf

1.37 MB
Binary file not shown.

cogs/memes/bruh.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import discord
22
from discord.ext import commands
33
from discord.utils import MISSING
4+
from discord import app_commands
45

56
from PIL import Image
67
from io import BytesIO
@@ -16,6 +17,7 @@ class BruhCommand(commands.Cog):
1617
usage="`/bruh <изображение> <текст>",
1718
help="### Пример:\n`/bruh` `image.png` `Пей горн`"
1819
)
20+
@app_commands.default_permissions(discord.Permissions.administrator)
1921

2022
async def bruh(
2123
self,

cogs/memes/demotivator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import discord
22
from discord.ext import commands
33
from discord.utils import MISSING
4+
from discord import app_commands
45

56
from PIL import Image
67
from io import BytesIO
@@ -16,6 +17,7 @@ class DemotivatorCommand(commands.Cog):
1617
usage="`/demotivator <изображение> <большой текст> [маленький текст]`",
1718
help="### Пример:\n`/demotivator` `image.png` `SAY GEX` `pay gorn`"
1819
)
20+
@app_commands.default_permissions(discord.Permissions.administrator)
1921

2022
async def demotivator(
2123
self,

cogs/memes/impact.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@
66
from PIL import Image
77
from io import BytesIO
88

9-
from utils import handle_errors, ImageText, edit_image, closest_match, no_ping
9+
from utils import handle_errors, ImageText, edit_image, no_ping
1010
from cogs.general.gif import GifizeView
1111

12-
positions = [app_commands.Choice(name="Верх", value="up"), app_commands.Choice(name="Низ", value="down")]
13-
positions_aliases = {
14-
"up": ["верх", "в"],
15-
"down": ["низ", "н"]
16-
}
17-
1812

1913
class ImpactCommand(commands.Cog):
2014
@commands.hybrid_command(
@@ -24,41 +18,39 @@ class ImpactCommand(commands.Cog):
2418
help="### Пример:\n`/impact image.png пей горн Низ`"
2519
)
2620
@app_commands.describe(
27-
text="Текст (до 500 символов)"
21+
top_text="Верхний текст (до 500 символов)",
22+
bottom_text="Нижний текст (до 500 символов)"
2823
)
24+
@app_commands.default_permissions(discord.Permissions.administrator)
2925

3026
async def impact(
3127
self,
3228
ctx: commands.Context,
3329
image: discord.Attachment,
34-
text: str,
35-
position: str="down"
30+
top_text: str="",
31+
bottom_text: str=""
3632
):
37-
text = text[:500]
33+
top_text = top_text[:500]
34+
bottom_text = bottom_text[:500]
3835

3936
if not image.content_type or "image" not in image.content_type:
4037
raise Exception("Not image")
4138
await ctx.defer()
4239
extension = image.filename.split(".")[-1]
4340

44-
position = closest_match(position, positions_aliases)
4541
impacted = edit_image(
4642
Image.open(BytesIO(await image.read())),
4743
extension,
4844
impact,
49-
text=text,
50-
position=position
45+
top_text=top_text,
46+
bottom_text=bottom_text
5147
)
5248
impacted_discorded = discord.File(impacted, filename=image.filename)
5349
await ctx.reply(
5450
file=impacted_discorded,
5551
view=GifizeView() if extension != "gif" else MISSING,
5652
allowed_mentions=no_ping
5753
)
58-
59-
@impact.autocomplete(name="position")
60-
async def position_default_choices(self, ctx, curr):
61-
return positions
6254

6355
@impact.error
6456
async def impact_error(self, ctx, error):
@@ -70,33 +62,42 @@ async def impact_error(self, ctx, error):
7062
])
7163

7264

73-
def impact(image: Image.Image, text: str, position: str):
65+
def impact(image: Image.Image, top_text: str, bottom_text: str):
7466
font = "assets/memes/impact.ttf"
75-
size = int((((image.width+image.height)/2)/10) / max(1, (len(text)/25)*0.5))
67+
get_size = lambda text: int((((image.width+image.height)/2)/10) / max(1, (len(text)/25)*0.5))
68+
top_size = get_size(top_text)
69+
bottom_size = get_size(bottom_text)
7670
color = (255, 255, 255)
7771
width = image.size[0]
7872
height = image.size[1]
79-
padding = int(height/12)
80-
text_width = width - padding * 2
73+
padding = int(height/16)
74+
text_width = width - padding
8175

8276
image = image.convert(mode="RGBA")
8377

8478
# Calculate required heights first
8579
impact_text = ImageText(image, anchor="ma")
8680

87-
if position == "down":
81+
if bottom_text != "":
8882
text_height = impact_text.get_height(
89-
(int(width/2), 0), text,
90-
text_width, font, size,
91-
stroke_width=int(size/16),
83+
(int(width/2), 0), bottom_text,
84+
text_width, font, bottom_size,
85+
stroke_width=int(bottom_size/16),
86+
stroke_fill=(0, 0, 0, 255)
87+
)
88+
y = height - padding - text_height
89+
impact_text.write_text_box(
90+
(int(width/2), y), bottom_text,
91+
text_width, font, bottom_size, color,
92+
stroke_width=int(bottom_size/16),
9293
stroke_fill=(0, 0, 0, 255)
9394
)
94-
padding = height - padding - text_height
9595

96-
impact_text.write_text_box(
97-
(int(width/2), padding), text,
98-
text_width, font, size, color,
99-
stroke_width=int(size/16),
96+
if top_text != "":
97+
impact_text.write_text_box(
98+
(int(width/2), padding), top_text,
99+
text_width, font, top_size, color,
100+
stroke_width=int(top_size/16),
100101
stroke_fill=(0, 0, 0, 255)
101102
)
102103

cogs/memes/soyjak.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import discord
22
from discord.ext import commands
33
from discord.utils import MISSING
4+
from discord import app_commands
45

56
from PIL import Image
67
from io import BytesIO
@@ -19,6 +20,7 @@ class SoyjakCommand(commands.Cog):
1920
usage="`/soyjak <изображение>`",
2021
help="### Пример:\n`/soyjak image.png`"
2122
)
23+
@app_commands.default_permissions(discord.Permissions.administrator)
2224

2325
async def soyjak(self, ctx: commands.Context, image: discord.Attachment):
2426
if not image.content_type or "image" not in image.content_type:

cogs/memes/speechbubble.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class SpeechbubbleCommand(commands.Cog):
4444
transparent2="Прозрачность второго спичбаббла",
4545
direction2="Положение стрелки второго спичбаббла",
4646
)
47+
@app_commands.default_permissions(discord.Permissions.administrator)
4748

4849
async def speechbubble(
4950
self,

0 commit comments

Comments
 (0)