forked from srli/image_steganography
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteganography.py
More file actions
55 lines (42 loc) · 1.83 KB
/
steganography.py
File metadata and controls
55 lines (42 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""A program that encodes and decodes hidden messages in images through LSB steganography"""
from PIL import Image, ImageFont, ImageDraw
import textwrap
def decode_image(file_location="images/encoded_sample.png"):
"""Decodes the hidden message in an image
file_location: the location of the image file to decode. By default is the provided encoded image in the images folder
"""
encoded_image = Image.open(file_location)
red_channel = encoded_image.split()[0]
x_size = encoded_image.size[0]
y_size = encoded_image.size[1]
decoded_image = Image.new("RGB", encoded_image.size)
pixels = decoded_image.load()
for i in range(x_size):
for j in range(y_size):
pass #TODO: Fill in decoding functionality
decoded_image.save("images/decoded_image.png")
def write_text(text_to_write, image_size):
"""Writes text to an RGB image. Automatically line wraps
text_to_write: the text to write to the image
image_size: size of the resulting text image. Is a tuple (x_size, y_size)
"""
image_text = Image.new("RGB", image_size)
font = ImageFont.load_default().font
drawer = ImageDraw.Draw(image_text)
#Text wrapping. Change parameters for different text formatting
margin = offset = 10
for line in textwrap.wrap(text_to_write, width=60):
drawer.text((margin,offset), line, font=font)
offset += 10
return image_text
def encode_image(text_to_encode, template_image="images/samoyed.jpg"):
"""Encodes a text message into an image
text_to_encode: the text to encode into the template image
template_image: the image to use for encoding. An image is provided by default.
"""
pass #TODO: Fill out this function
if __name__ == '__main__':
print("Decoding the image...")
decode_image()
print("Encoding the image...")
encode_image()