How to hide text into image using Python

Free Python Code - Aug 26 '23 - - Dev Community

Hi ๐Ÿ™‚๐Ÿ–

Today i will share with you How to hide text into image using Python.

First, we need to know the science behind this idea called steganography.

Steganography is the art and science of writing hidden messages in such a way that no one, apart from the sender and intended recipient, suspects the existence of the message, a form of security through obscurity. Consequently, functions provided by Stegano only hide messages, without encryption. Steganography is often used with cryptography.

Second, after we know what steganography is,
we need module or liblary
To hide text into image you need to install module called stegano.

install from here : pip install stegano

If you want to hide text you need a PNG image if your image extintion is JPG or any thing else.

you need to convert it using this code :


from PIL import Image

img = Image.open('test.jpg')
img.save('test.png')

Enter fullscreen mode Exit fullscreen mode

Now you have a PNG image you can hide your message ๐Ÿ˜Ž

from stegano.lsb import lsb

secret = lsb.hide('test.png', 'this is message to test ๐Ÿ™‚')
secret.save('out.png')

Enter fullscreen mode Exit fullscreen mode

To extract the hidden message from out.png image you need to use function called reveal

from stegano.lsb import lsb

text = lsb.reveal('out.png')
print(text)
Enter fullscreen mode Exit fullscreen mode

Result

this is message to test รป
Enter fullscreen mode Exit fullscreen mode

Now we're done ๐Ÿค—

Don't forget to like and follow ๐Ÿ™‚

Support me on PayPal ๐Ÿค—
https://www.paypal.com/paypalme/amr396

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .