Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Png to Div
import png
import sys
import itertools
argvs = sys.argv
def main():
if len(argvs) != 2:
print "Usage: python myself.py [file *.png]"
exit()
if argvs[1].split(".")[1] != "png":
print "Oops !! It uses PNG File...Sorry..."
pr = png.Reader(file=open(argvs[1],'rb'))
png_x,png_y,pixels,meta = pr.asRGB8()
rgb_data = [0,0,0]
pixels,pixels2 = itertools.tee(pixels)
for pixel in pixels:
for i in range(png_x):
for j in range(3):
rgb_data[j] = hex(pixel[i * 3 + j]).replace("0x","").upper()
if len(rgb_data[j]) == 1:rgb_data[j] = "0" + rgb_data[j]
print "<div style='margin:0px;padding:0px;float:left;width:3px;height:3px;background-color:#" + rgb_data[0] + rgb_data[1] + rgb_data[2] + "'></div>"
print "<div style='clear:left'></div>"
for pixel in pixels2:
for i in range(png_x):
for j in range(3):rgb_data[j] = hex(pixel[i * 3 + j]).replace("0x","").upper()
print "<span style='color:#" + rgb_data[0] + rgb_data[1] + rgb_data[2] + "'>#</span>"
print "<div style='clear:left'></div>"
if __name__ == '__main__':main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment