示例#1
0
def create_stegano_image(original_image, data_to_hide, cipher_key=""):
    """
    # PARAMETERS:
    original_image - A string representing the full path to an RGB or RGBA format PNG Image file.
    data_to_hide   - A string representing the full path to a file that will be encoded into the original_image.
    cipher_key     - An optional string that will be used as the cipher key to encrypt the data prior to encoding
                     in the original image. Must be between 8 and 56 characters in length.

    # RETURNS:
    An image object
    """
    original_image, pixel_type = stegano.validate_image(original_image)
    data_to_hide = stegano.encrypt_data_if_needed(open(data_to_hide, 'rb').read(), cipher_key)
    image_encoded_with_data = original_image.copy()
    image_width, column_position, row_number = image_encoded_with_data.size[0], 0, 0
    for pixel in stegano.encode_data_in_image(image_encoded_with_data.getdata(), data_to_hide, pixel_type):
        image_encoded_with_data.putpixel((column_position, row_number), pixel)
        column_position, row_number = stegano.update_pixel_position(column_position, row_number, image_width)
    return image_encoded_with_data
 def test_pixels_of_encoded_image_are_properly_returned_from_encode_data_in_image_using_rgba_image(self):
     image_data = Image.open("tests/test_resources/rgba_image.png").getdata()
     data_to_hide = "A"
     expected_return_value = [(254, 255, 254, 0), (254, 254, 254, 0), (254, 255, 255, 0)]
     self.assertEqual(list(stegano.encode_data_in_image(image_data, data_to_hide, "rgba")), expected_return_value)
 def test_pixels_of_encoded_image_are_properly_returned_from_encode_data_in_image_using_rgb_image(self):
     image_data = Image.open("tests/test_resources/rgb_image.png").getdata()
     data_to_hide = "AB"
     expected_return_value = [(2, 3, 2), (0, 0, 0), (6, 7, 6), (8, 9, 8), (0, 0, 0), (3, 2, 3)]
     self.assertEqual(list(stegano.encode_data_in_image(image_data, data_to_hide, "rgb")), expected_return_value)