I made a little module that I have ended up using a lot. It can encode strings of text into RGB color values, store them as pixels on a .png image, and then save that image for consistent storage. Once you send the message to someone, they can use the decode function and it will iterate over the darkened pixels, and return the string of text that that image has stored in itself. Pretty cool?
Here is the source...
# coding: utf-8 import Image def bencode(filename,plain_text): # returns true or false depending on if it successfully saves the photo. try: coded_image_width = len(plain_text)*5 bioMessage = Image.new("RGB",(coded_image_width,1),(255,0,0)) bioMessageLoaded = bioMessage.load() newPixelPosition = [0,0] for char in plain_text: asciiEdition = ord(char) bioMessageLoaded[newPixelPosition,0] = (asciiEdition,asciiEdition,asciiEdition) newPixelPosition += 5 bioMessage.save(filename) return True except: return False def bedecode(coded_image): # returns a string of the decoded message. encodedPNG = Image.open(coded_image) encodedPNGLoaded = encodedPNG endtxt = "" newGrabPosition = [0,0] charsAmount = encodedPNG.size / 5 for reading in range(charsAmount): pixel = encodedPNG.getpixel((newGrabPosition,0)) endtxt += chr(pixel) newGrabPosition += 5 return endtxt
Moe last edited by Moe
Now to turn this into a steganography module ;)
- bug fixes and optimisations
Phuket2 last edited by
@AtomBombed , would be nice to see one of your ideas for usage implemented. Whilst you can see very clearly your vision, not everyone will. Including me 😱
TutorialDoctor last edited by TutorialDoctor
I made a post about this a while ago, because I had the same idea. Forgot about it until now:
I wonder how well it works...
Works nicely for a "Hello World" text. Now I am going to try to save this code snippet you posted.
WOW! This is an awesome script! This is exactly what I had thought about. It is fast also and the image sizes are very small.
I used this to execute an image as python code using the
You might have to change your photo soon to something other than a QR code. I tried to do this with QR codes, but the images became very messy. Awesome code!
Webmaster4o last edited by
@Moe *steganography ;)
Moe last edited by
Webmaster4o last edited by
@Moe You're right. Most native english speakers couldn't tell you the difference either. Not meaning to be rude, just pointing it out for you :)
Moe last edited by
@Webmaster4o I should have put a smiley at the end of that, I just couldn't resist to be the stereotypical un-fun German :P I know that you were just kindly poiting out a mistake :)
Thanks to everyone for your uplifting support! I am actually converting the code over to a faster version that can almost half the time of the current version. Also, it will have multiple lines of pixels instead of one continuous line. There will also be no red pixel whitespace in between coded gray pixels. This will decrease the filesize of images, and will make the images less suspicious. I will post an update when this version is ready.
@TutorialDoctor whenever I get a suggestion to fix something, I cut right to it. What do you mean about the QR codes, and being messy?
TutorialDoctor last edited by
@AtomBombed. This technology can very well replace QR codes. When storing large amounts of data in a QR code, the image becomes really dense (don't know how to explain it).
If you designed this code yourself, you should give it a name, and change your logo to that (because this is cool)!
chibill last edited by chibill
I took this code and made some edits ti where it uses all the rgb values to store that data. And I am already planing a QR code like system with it,
My version actually can compress some files a bit. Also very good work. I will post my code in a separate post and link back to here. My code still have some of the same variable schemes as yours.
EDIT: Link to my thread. PicEncode
JonB last edited by
If you are emailing the pictures, such that there is no corruption of the image, you are just as well off sending the file directly.
QR codes are designed to be low density but highly robust. The typical QR Will work with a lo quality photograph taken in poor lighting, low contrast, perhaps at an angle, maybe full of distortion, etc. It has embedded alignment marks, edges provide "timing" information, and error correction, etc.
I think trying to use color information will backfire, if you want these to be photographable, unless you keep the color channel to only a few bits, because color accuracy is notoriously difficult.
@JonB this is what I've been working on for a while. Compression software used by large companies such as Google could corrupt the data when someone is using Gmail or something of that nature.
Don't worry, I've taken everything into consideration.
I have fixed the software's "robustability" issues. It originally used the
ord. These have issues when converting pixels' RGB color values. When sending images that have been encoded across platforms like Gmail, Google would compress the image file to make all of the pixels' colors round to the nearest supported pixel. When decoding these images, it gave unexpected text results.
I have, of course, fixed this. I made my own character database. When converting pixel color values into their respective ASCII character codes, I have made a layer that the program will run through and make sure that colors nearby each other will retain the same text. It's quite simple, actually.
For example, if I had an image that was compressed to the nearest color supported color value, then it would still recognize it's contained character. If I ran over a pink pixel with a luminosity of +2 to the base hue, then it would recognize that character value as the same character value as a pink pixel with a base hue, and no luminosity changes.
All of this might be hard to understand, but I will probably release a table/chart of all of the pixel color values, and what characters they convert to.