-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathdotify.py
More file actions
82 lines (72 loc) · 2 KB
/
dotify.py
File metadata and controls
82 lines (72 loc) · 2 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from PIL import Image, ImageDraw
import io
import asyncio
import logging
from .. import loader, utils
logger = logging.getLogger(__name__)
class DotifyMod(loader.Module):
"""Image to dot
.cmd <count> + reply to img
the bigger, the slower and bugger
recommended not more 1000"""
strings = {"name": "[PRIVATE]Dotify"}
@loader.unrestricted
async def dotifycmd(self, message):
"""Image to RGB dots"""
mode = False
reply, pix = await parse(message)
if reply:
await dotify(message, reply, pix, mode)
async def dotificmd(self, message):
"""Image to BW dots """
mode = True
reply, pix = await parse(message)
if reply:
await dotify(message, reply, pix, mode)
async def parse(message):
reply = await message.get_reply_message()
if not reply:
await message.edit("<b>Reply to Image!</b>")
return None, None
args = utils.get_args(message)
pix = 100
if args:
args=args[0]
if args.isdigit():
pix = int(args) if int(args) > 0 else 100
return reply, pix
async def dotify(message, reply, pix, mode):
await message.edit("<b>Putting dots...</b>")
count = 24
im_ = Image.open(io.BytesIO(await reply.download_media(bytes)))
if im_.mode == "RGBA":
temp = Image.new("RGB", im_.size, "#000")
temp.paste(im_, (0, 0), im_)
im_ = temp
im = im_.convert("L")
im_ = im if mode else im_
[_.thumbnail((pix, pix)) for _ in[im, im_]]
w, h = im.size
img = Image.new(im_.mode, (w*count+(count//2), h*count+(count//2)), 0)
draw = ImageDraw.Draw(img)
def cirsle(im, x, y, r, fill):
x += r//2
y += r//2
draw = ImageDraw.Draw(im)
draw.ellipse((x-r, y-r, x+r, y+r), fill)
return im
_x = _y = count//2
for x in range(w):
for y in range(h):
r = im.getpixel((x, y))
fill = im_.getpixel((x, y))
cirsle(img, _x, _y, r//count, fill)
_y += count
_x += count
_y = count//2
out = io.BytesIO()
out.name = "out.png"
img.save(out)
out.seek(0)
await reply.reply(file=out)
await message.delete()