-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhide.py
More file actions
39 lines (35 loc) · 1.21 KB
/
hide.py
File metadata and controls
39 lines (35 loc) · 1.21 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
from PIL import Image
import numpy as np
import sys, os
from progress_bar import ProgressBar
def set_px(pos, bit, img):
# avoids modifying thumbnail
size = img.shape[0]*img.shape[1] - 4096
rgb = pos//size
if rgb > 2:
raise IndexError("Position is too large for image")
n_pos = pos % size + 4096
x,y = n_pos // img.shape[1], n_pos % img.shape[1]
img[x][y][rgb] = img[x][y][rgb] & 254
img[x][y][rgb] = img[x][y][rgb] | bit
with Image.open(sys.argv[1]) as img:
with open(sys.argv[2], 'r') as input_txt:
arrimg = np.array(img)
pos = 0
tasks = int(os.popen("wc -c " + sys.argv[2]).read().split(" ")[0])
for c in str(tasks)+"|":
for i in range(8):
bit = (ord(c) & 1 << i) >> i
set_px(pos, bit, arrimg)
pos += 1
pb = ProgressBar(tasks)
pb.begin()
for line in input_txt:
for char in line:
for i in range(8):
bit = (ord(char) & 1 << i) >> i
set_px(pos, bit, arrimg)
pos += 1
pb.add_progress()
output_img = Image.fromarray(arrimg)
output_img.save(sys.argv[3])