Convert Images to text and text back to images
When we convert images to/from text we use base64 and import python you can use base64 by
So this script will open the image from the first argument and save to readable text version as output.txtimport base64
import sys, base64
img = open(sys.argv[1], 'r')
txt = img.read()
txt2 = base64.b64encode(txt)
txtfile = open("output.txt", 'w')
txtfile.write(txt2)
#print txt2
If you uncomment the last line by removing the '#' it will print out the text value of the image.
And this
import sys, base64Will open the text file as the first argument and output the image to 'output.png'
img = open(sys.argv[1], 'r')
txt = img.read()
txt2 = base64.b64decode(txt)
txtfile = open("output.png", 'w')
txtfile.write(txt2)
Download
No comments:
Post a Comment