Skip to content

Commit

Permalink
Making unpack image take into account image modes that would have a d…
Browse files Browse the repository at this point in the history
…epth of only 1.
  • Loading branch information
MotaDan committed Oct 12, 2016
1 parent d06bd83 commit 75424ad
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions steganographer/steganographer.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,14 @@ def unpack_image(pixels):
"""Flatten out pixels and returns a tuple. The first entry is the size of each pixel."""
unpacked_pixels = []

for pix in pixels:
for val in pix:
unpacked_pixels.append(val)
try:
for pix in pixels:
for val in pix:
unpacked_pixels.append(val)

return len(pixels[0]), bytes(unpacked_pixels)
return len(pixels[0]), bytes(unpacked_pixels)
except TypeError:
return 1, bytes(pixels)


def pack_image(pixels):
Expand Down Expand Up @@ -168,7 +171,7 @@ def open_image_file(fname):
"""Reads the file fname and returns bytes for all it's data."""
try:
img = Image.open(fname)
pixels = img.getdata()
pixels = list(img.getdata())
return unpack_image(pixels)

except FileNotFoundError:
Expand Down

0 comments on commit 75424ad

Please sign in to comment.