Files
Ultroid-fork/plugins/resize.py
Danish 68839e9dd0 Ultroid v0.0.7 2021/05/22
Co-authored-by: New-dev0 <New-dev0@notavailable.live>
Co-authored-by: Danish <danish@ultroid.tech>
Co-authored-by: Amit Sharma <48654350+buddhhu@users.noreply.github.com>
Co-authored-by: Programming Error <error@notavailable.live>
Co-authored-by: Aakash <BLUE-DEVIL1134@users.noreply.github.com>
Co-authored-by: Aditya <me@xditya.me>
Co-authored-by: sppidy <sppidy@users.noreply.github.com>
Co-authored-by: Arnab Paryali <Arnabxd@users.noreply.github.com>
Co-authored-by: divkix <divkix@users.noreply.github.com>
Co-authored-by: hellboi_atul <hellboi-atul@users.noreply.github.com>
2021-05-22 22:21:41 +05:30

66 lines
1.8 KiB
Python

# Ultroid - UserBot
# Copyright (C) 2020 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 *
@ultroid_cmd(pattern="size$")
async def size(e):
r = await e.get_reply_message()
if not (r and r.media):
return await eor(e, "`Reply To image`")
k = await eor(e, "`Processing...`")
if hasattr(r.media, "document"):
img = await ultroid_bot.download_media(r, thumb=-1)
else:
img = await ultroid_bot.download_media(r.media)
im = Image.open(img)
x, y = im.size
await k.edit(f"Dimension Of This Image Is\n`{x} : {y}`")
os.remove(img)
@ultroid_cmd(pattern="resize ?(.*)")
async def size(e):
r = await e.get_reply_message()
if not (r and r.media):
return await eor(e, "`Reply To image`")
sz = e.pattern_match.group(1)
if not sz:
return await eod(f"Give Some Size To Resize, Like `{HNDLR}resize 720 1080` ")
k = await eor(e, "`Processing...`")
if hasattr(r.media, "document"):
img = await ultroid_bot.download_media(r, thumb=-1)
else:
img = await ultroid_bot.download_media(r.media)
sz = sz.split()
if not len(sz) == 2:
return await eod(f"Give Some Size To Resize, Like `{HNDLR}resize 720 1080` ")
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 ultroid_bot.send_file(e.chat_id, img)
os.remove(img)
await k.delete()
HELP.update({f"{__name__.split('.')[1]}": f"{__doc__.format(i=HNDLR)}"})