-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcolorBit.py
More file actions
30 lines (29 loc) · 1.05 KB
/
colorBit.py
File metadata and controls
30 lines (29 loc) · 1.05 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
from .. import loader, utils
from PIL import Image
from io import BytesIO as io
class colorBitMod(loader.Module):
strings = {"name": "colorBit"}
async def cbitcmd(self, message):
""".cbit <число от 0 до 255"""
reply = await message.get_reply_message()
if not reply or not reply.file or not "image" in reply.file.mime_type:
return await message.edit("<b>Reply to image!</b>")
x = utils.get_args_raw(message)
x = int(x) if x.isdigit() else 8
if x <= 0 or x >= 256:
x = 8
x = 256//x
im = Image.open(io(await reply.download_media(bytes)))
w, h = im.size
mode = im.mode
out = []
await message.edit("<b>Processing...</b>")
for bit in list(im.tobytes()):
bit = list(range(0, 256+x, x))[bit//x]
out.append(bit)
image = Image.frombytes(mode, (w, h), bytes(out))
output = io()
image.save(output, "PNG")
output.seek(0)
await message.delete()
await reply.reply(file=output)