Minor Changes

I changed how the status of the conversion appears, and it now shows you how much the data's been compressed once it's been converted to a PNG file.
This commit is contained in:
Skye Stevenson 2018-10-27 18:54:46 -07:00
parent b5b2c1e4b9
commit 81add95db4
2 changed files with 22 additions and 8 deletions

View File

@ -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")
#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))

View File

@ -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()