Created
January 31, 2014 13:00
-
-
Save goulu/1bc4aa8ec1221a4c3465 to your computer and use it in GitHub Desktop.
Least efficient way to display an image in HTML
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
from PIL import Image | |
im = Image.open("img2htmltable.png") | |
mat=im.load() | |
width, height = im.size | |
file=open('img2htmltable.htm','w') | |
file.write('<table width="%d"px height="%d"px cellpadding=0 cellspacing=0 style="border-collapse: collapse;">'%(width,height)) | |
for line in range(height): | |
file.write('<tr>') | |
for col in range(width): | |
color='#%02x%02x%02x' % mat[col,line] | |
file.write('<td width="1px" height="1px" bgcolor="%s"></td>'%color) | |
file.write('</tr>\n') | |
file.write('</table>') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment