diff --git a/DataToPixel_RGB.py b/DataToPixel_RGB.py index e3818e4..53ef1d7 100644 --- a/DataToPixel_RGB.py +++ b/DataToPixel_RGB.py @@ -5,6 +5,10 @@ # each ASCII character takes up a 0-127 space, meaning we can fit at least 1 ASCII character into each channel of a given pixel in an image! # we need to assign the numeric value of a series of ASCII characters to each of the channels of each pixel of an image! +# ensure proper division +from __future__ import division +import os + # make list from string fileName = raw_input("Give me a file to pixelize:\n") #fileName = "" @@ -18,12 +22,14 @@ listLength = len(dataList) import math width = int(math.ceil(math.sqrt(listLength/3))) +#width = int(math.ceil(listLength/3))+1 #print "width: " + str(width) # make the image from PIL import Image image = Image.new('RGB',(width,width),color=0) +#image = Image.new('RGB',(width,1),color=0) # load the temp image and store the ASCII value in one of its pixels px = image.load() @@ -55,10 +61,18 @@ for q in range(0,width): #print gVal #print bVal - print str(index) + "/" + str(listLength) + " done" + #print str(index+1) + "/" + str(listLength) + " done" + currentProgress = 100 * ((index + 1) / listLength) + print("{:.4f}%".format(currentProgress)) index += 3 +print("Finished!") - -image.show() -image.save("asciiConverted_RGB.png") \ No newline at end of file +#image.show() +image.save("CONVERTED.png") + +oldFileSize = os.path.getsize(fileName) +newFileSize = os.path.getsize("CONVERTED.png") +fileSizeReduction = 100 * (1 - (newFileSize / oldFileSize)) + +print("File size reduced by {:.2f}%".format(fileSizeReduction)) \ No newline at end of file diff --git a/PixelToData_RGB.py b/PixelToData_RGB.py index c3c6be7..c40e6dc 100644 --- a/PixelToData_RGB.py +++ b/PixelToData_RGB.py @@ -1,7 +1,7 @@ #fileName = raw_input("Give me a file to pixelize:\n") from PIL import Image -image = Image.open("asciiConverted_RGB.png") +image = Image.open("CONVERTED.png") # get image width width, height = image.size @@ -13,7 +13,7 @@ stringOutput = "" index = 0 -for q in range(0,width): +for q in range(0,height): for i in range(0,width): # stringOutput += chr(px[i,q]) @@ -32,12 +32,12 @@ for q in range(0,width): #print "-" - print str(index) + "/" + str(width*width) + " done" + print str(index+1) + "/" + str(width*width) + " done" index += 1 #print stringOutput # save to file -outFile = open("TESTCONVERT.txt","w") +outFile = open("CONVERTBACK.obj","w") outFile.write(stringOutput) outFile.close() \ No newline at end of file