-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinklib.py
39 lines (35 loc) · 979 Bytes
/
linklib.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
from PIL import Image
def matrixlink(link, name):
wi = 8
he = len(link)
matr = Image.new(mode="1", size=(wi, he))
vals = []
for i in link:
if ord(i) < 256:
asciicode = str(bin(ord(i)))[2:]
if len(asciicode) < 8:
asciicode = ("0" * (8 - len(asciicode))) + asciicode
vals.append(asciicode)
x = 0
y = 0
for o in vals:
for p in o:
matr.putpixel((x, y), value=int(p))
x += 1
x = 0
y += 1
matr.save(f"out/{name}.png")
def getlink(image):
img = Image.open(image)
link = ""
for i in range(img.height):
parola = ""
for j in range(img.width):
if img.getpixel((j, i)) == 255:
val = 1
else:
val = 0
parola = parola + str(val)
parola = int(parola, 2)
link = link + chr(parola)
return link