From a2cab3a9f592a9b707b85e4fb26262efcb3f82be Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Wed, 30 Mar 2011 22:11:33 +0200 Subject: [PATCH] Bug fix. Bad argument in *hide* function when used as module. --- stegano/slsb.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/stegano/slsb.py b/stegano/slsb.py index 1c63ac6..a76457a 100755 --- a/stegano/slsb.py +++ b/stegano/slsb.py @@ -30,11 +30,12 @@ from PIL import Image import tools -def hide(img, message): +def hide(input_image_file, message): """ Hide a message (string) in an image with the LSB (Least Significant Bit) technique. """ + img = Image.open(input_image_file) encoded = img.copy() width, height = img.size index = 0 @@ -67,11 +68,12 @@ def hide(img, message): return encoded -def reveal(img): +def reveal(input_image_file): """ Find a message in an image (with the LSB technique). """ + img = Image.open(input_image_file) width, height = img.size buff, count = 0, 0 bitab = [] @@ -96,6 +98,15 @@ def reveal(img): return "".join(bitab)[len(str(limit))+1:] return "" +def write(image, output_image_file): + """ + """ + try: + image.save(output_image_file) + except Exception, e: + # If hide() returns an error (Too long message). + print e + if __name__ == '__main__': # Point of entry in execution mode. from optparse import OptionParser @@ -135,8 +146,7 @@ if __name__ == '__main__': elif options.secret_message == "" and options.secret_file != "": secret = tools.binary2base64(options.secret_file) - img = Image.open(options.input_image_file) - img_encoded = hide(img, secret) + img_encoded = hide(options.input_image_file, secret) try: img_encoded.save(options.output_image_file) except Exception, e: @@ -144,8 +154,7 @@ if __name__ == '__main__': print e elif options.reveal: - img = Image.open(options.input_image_file) - secret = reveal(img) + secret = reveal(options.input_image_file) if options.secret_binary != "": data = tools.base642binary(secret) with open(options.secret_binary, "w") as f: