Image based Steganography using Python Programming

In this article, we will learn about image-based steganography using Python. Stenography is a method of hiding a text behind audio, video, and images. This is used to enhance the security and protection from false copyright claims.

We are achieving this with the help of the encoding feature available in the stepic module available in Python. For displaying and viewing purposes we use the PIL (Python Imaging Library) available in Python.

Ide preferred − Jupyter notebook

Importing all the dependencies −

>>> from PIL import Image

>>> import stepic

In this article, we will encode text on the image given below. Please download the image below and save as “logo.png” in the jupyter notebook localhost folder.

You can use any image of your choice. You just need to specify the path of your image within double-quotes.

>>> img ='logo.png')

Here the Image function allows us to open the “image” on which steganography needs to be performed. The .show() function allows us to see the image in the form of a popup as shown below.

Now using the stepic module we encode a message into 8-bit binary data using the ASCII value. For encoding the .encode() function is used which accepts two parameters i.e. image and message.

We use the .save() function to save the hidden message into our original image.

>>> img1 = stepic.encode(im, b'Tutorialspoint')
>>>'logo.png', 'PNG')

Now let’s display the encoded image.

>>> img1 ='logo.png')

I think you observe no change in the two images. This is because the message is hidden and isn’t visible directly.

To verify that you have successfully encoded the message go through the code below.

>>> im2 ='logo.png')
>>> message_hidden = stepic.decode(im2)
>>> print(message_hidden)


Here hidden/encoded message is displayed by the built-in decoder of stepic module available in Python.


In this article, we learned about image-based Steganography using stepic and PIL Modules available in Python 3.x. Or earlier.

Published on 11-Sep-2019 14:57:28