1
0
Fork 0
mirror of https://github.com/GeoffreyFrogeye/steginack.git synced 2024-12-21 22:30:36 +01:00

Hiding image

Untested
This commit is contained in:
Geoffrey Frogeye 2015-04-23 09:22:24 +02:00
parent 100725d05c
commit 63a4af6e0f

View file

@ -2,20 +2,43 @@
from PIL import Image
import argparse
from eta import ETA
get_bin = lambda x, n: x >= 0 and str(bin(x))[2:].zfill(n) or "-" + str(bin(x))[3:].zfill(n)
# From http://stackoverflow.com/a/21732313/2766106
def hideInFile(infile, hidefile, bits, outfile):
inim = Image.open(infile)
hideim = Image.open(hidefile)
assert inim.size == hideim.size, "Both image must be of the same size"
assert 0 <= bits <= 8
outim = Image.new('RGB', inim.size)
eta = ETA(inim.size[0] * inim.size[1])
for x in range(inim.size[0]):
for y in range(inim.size[1]):
incol = inim.getpixel((x, y))
hidecol = inim.getpixel((x, y))
outcol = []
for cp in range(len(incol)):
inbyt = get_bin(incol[cp], 8)
hidebyt = get_bin(hidecol[cp], 8)
outbyt = list(inbyt)
for bit in range(bits):
outbyt[-bit - 1] = inbyt[1]
outcol.append(int(''.join(outbyt), 2))
outim.putpixel((x, y), tuple(outcol))
eta.print_status(x * inim.size[1] + y)
eta.done()
inim.close()
hideim.close()
outim.save(outfile, 'PNG')
def inverseFile(infile, bits, outfile):
inim = Image.open(infile)
outim = Image.new('RGB', inim.size)
assert 0 <= bits <= 8
inim.close()
outim.save(outfile, 'PNG')