Skip to content

Instantly share code, notes, and snippets.

@goulu
Created January 31, 2014 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goulu/1bc4aa8ec1221a4c3465 to your computer and use it in GitHub Desktop.
Save goulu/1bc4aa8ec1221a4c3465 to your computer and use it in GitHub Desktop.
Least efficient way to display an image in HTML
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