Post: [Python] Image Storage (text) and Recreation (from text) [xerotic]
05-10-2011, 04:41 PM #1
(adsbygoogle = window.adsbygoogle || []).push({}); My program reads an image file and grabs its pixel data (RGBA). It then stores it in a text file. The second part of the program recreates the image based on the pixel data. So if you want to 'secretly trade images' or something like that, this method works to a degree. To make it safer,
Well.. try it out and tell me what you think!


    from PIL import Image

print 'Image Decoder/Recreator from xerotic. Original idea from BlueMelon.'

def main():
x = int(raw_input("\n\n1.) Grab content\n2.) Recreate image\n\nChoice: "))
if x == 1:
Decode()
elif x == 2:
Create()
else:
print 'Invalid Choice\n--------------\n'

def Decode():
_name = raw_input("File Name (must be in current directory): ")
txtName = raw_input("Resulting file name: ")
im = Image.open(_name)
im.getcolors()
q = list(im.getdata())
q.insert(0, im.size)
store = open(txtName+".txt", "w")
for i in q:
store.write(str(i)+"\n")
store.close()

def Create():
pix = []
_filename = raw_input("File Name for Image: ")
dataFile = raw_input("Image data file: ")
take = open(dataFile)
for line in take.readlines():
line = line.replace('\n', ''Winky Winky
pix.append(eval(line))
take.close()
h, w = pix.pop(0)
img = Image.new('RGBA',((h,w)))
pixeldata = img.load()
for y in xrange(h):
for x in xrange(w):
i = pix.pop(0)
pixeldata[x,y] = (i)
img.save(_filename+'.png','PNG'Winky Winky

while 1:
main()


Pastebin: You must login or register to view this content.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo