From a38f23509bd1554763c6dfe5854f0ebb6f27b81a Mon Sep 17 00:00:00 2001 From: panni Date: Thu, 21 Apr 2016 15:23:04 +0200 Subject: [PATCH] add optional auto_convert_rgb parameter to slsb.hide/slsbset.hide; add .idea to .gitignore --- .gitignore | 2 ++ stegano/slsb.py | 14 +++++++------- stegano/slsbset.py | 13 +++++++------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 1b1b84b..8255b2c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ syntax: glob *~ *.db +.idea/ + build/* Stegano.egg-info/* dist/* diff --git a/stegano/slsb.py b/stegano/slsb.py index ae2b42b..99a8bbb 100755 --- a/stegano/slsb.py +++ b/stegano/slsb.py @@ -35,7 +35,7 @@ try: except NameError: pass -def hide(input_image_file, message): +def hide(input_image_file, message, auto_convert_rgb=False): """ Hide a message (string) in an image with the LSB (Least Significant Bit) technique. @@ -43,12 +43,12 @@ def hide(input_image_file, message): img = Image.open(input_image_file) if img.mode != 'RGB': - print('The mode of the image is not RGB. Mode is {}'.format(img.mode)) - answer = input('Convert the image to RGB ? [Y / n]\n') or 'Y' - if answer.lower() == 'n': - raise Exception('Not a RGB image.') - else: - img = img.convert('RGB') + if not auto_convert_rgb: + print('The mode of the image is not RGB. Mode is {}'.format(img.mode)) + answer = input('Convert the image to RGB ? [Y / n]\n') or 'Y' + if answer.lower() == 'n': + raise Exception('Not a RGB image.') + img = img.convert('RGB') encoded = img.copy() width, height = img.size diff --git a/stegano/slsbset.py b/stegano/slsbset.py index 3daa128..b559896 100644 --- a/stegano/slsbset.py +++ b/stegano/slsbset.py @@ -36,7 +36,7 @@ try: except NameError: pass -def hide(input_image_file, message, generator_function): +def hide(input_image_file, message, generator_function, auto_convert_rgb=False): """ Hide a message (string) in an image with the LSB (Least Significant Bit) technique. @@ -45,11 +45,12 @@ def hide(input_image_file, message, generator_function): if img.mode != 'RGB': print('The mode of the image is not RGB. Mode is {}'.format(img.mode)) - answer = input('Convert the image to RGB ? [Y / n]\n') or 'Y' - if answer.lower() == 'n': - raise Exception('Not a RGB image.') - else: - img = img.convert('RGB') + if not auto_convert_rgb: + answer = input('Convert the image to RGB ? [Y / n]\n') or 'Y' + if answer.lower() == 'n': + raise Exception('Not a RGB image.') + + img = img.convert('RGB') img_list = list(img.getdata()) width, height = img.size