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])
x,y = pos // img.shape[1], pos % img.shape[1] return img[x][y][rgb] & 1 with Image.open(sys.argv[1]) as img: with open(sys.argv[2], "w+") as out: arrimg = np.array(img) pos = 0 cur_char = '' size_str = "" while cur_char != "|": ord_chr = 0 for i in range(8): bit = get_bit(pos, arrimg) pos += 1 ord_chr = ord_chr | bit << i cur_char = chr(ord_chr) size_str += cur_char size = int(size_str[:-1]) pb = ProgressBar(size) pb.begin() for i in range(size): ord_chr = 0 for i in range(8): bit = get_bit(pos, arrimg) pos += 1 ord_chr = ord_chr | bit << i out.write(chr(ord_chr)) pb.add_progress()