forked from AellyXD/Puii
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresize.py
64 lines (57 loc) · 1.82 KB
/
resize.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
✘ Commands Available -
•`{i}size <reply to media>`
To get size of it.
•`{i}resize <number> <number>`
To resize image on x, y axis.
eg. `{i}resize 690 960`
"""
from PIL import Image
from . import HNDLR, eor, get_string, os, puii_cmd
@puii_cmd(pattern="size$")
async def size(e):
r = await e.get_reply_message()
if not (r and r.media):
return await e.eor(get_string("ascii_1"))
k = await e.eor(get_string("com_1"))
if hasattr(r.media, "document"):
img = await e.client.download_media(r, thumb=-1)
else:
img = await r.download_media()
im = Image.open(img)
x, y = im.size
await k.edit(f"Dimension Of This Image Is\n`{x} x {y}`")
os.remove(img)
@puii_cmd(pattern="resize( (.*)|$)")
async def resize(e):
r = await e.get_reply_message()
if not (r and r.media):
return await e.eor(get_string("ascii_1"))
sz = e.pattern_match.group(1).strip()
if not sz:
return await eor(
f"Give Some Size To Resize, Like `{HNDLR}resize 720 1080` ", time=5
)
k = await e.eor(get_string("com_1"))
if hasattr(r.media, "document"):
img = await e.client.download_media(r, thumb=-1)
else:
img = await r.download_media()
sz = sz.split()
if len(sz) != 2:
return await eor(
k, f"Give Some Size To Resize, Like `{HNDLR}resize 720 1080` ", time=5
)
x, y = int(sz[0]), int(sz[1])
im = Image.open(img)
ok = im.resize((x, y))
ok.save(img, format="PNG", optimize=True)
await e.reply(file=img)
os.remove(img)
await k.delete()