Created
November 10, 2011 11:58
-
-
Save esehara/1354693 to your computer and use it in GitHub Desktop.
Png to Div
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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