-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathMirrorFlipV2.py
More file actions
46 lines (42 loc) · 1.25 KB
/
MirrorFlipV2.py
File metadata and controls
46 lines (42 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from PIL import Image, ImageOps
from .. import loader, utils
from io import BytesIO
from asyncio import sleep
class MirrorFlipMod(loader.Module):
strings = {"name": "MirrorFlip", 0:"<b>Reply to image.</b>"}
async def llcmd(self, m):
return await make(m, 1)
async def rrcmd(self, m):
return await make(m, 2)
async def uucmd(self, m):
return await make(m, 3)
async def ddcmd(self, m):
return await make(m, 4)
async def make(m, o):
r = await m.get_reply_message()
s = None
try:
s = await r.download_media(bytes, thumb=-1 if not r.sticker else None)
img = Image.open(BytesIO(s))
except:
pass
if not s:
return await utils.answer(m, MirrorFlipMod.strings[0])
await m.delete()
w, h = img.size
if o in [1, 2]:
if o == 2:
img = ImageOps.mirror(img)
part = img.crop([0, 0, w//2, h])
img = ImageOps.mirror(img)
else:
if o == 4:
img = ImageOps.flip(img)
part = img.crop([0, 0, w, h//2])
img = ImageOps.flip(img)
img.paste(part, (0, 0))
out = BytesIO()
out.name = "x.webp" if r.sticker else "x.png"
img.save(out)
out.seek(0)
return await r.reply(file=out)