''' Created on Jan 2, 2015 @author: Brett Paufler Copyright Brett Paufler This is pretty cool if I do say so myself perhaps a bit long for a name, but we can qualify import for archival purposes, I reduced the named down from page_image_rendered_as_table.py Needs an Image to Work... ''' import base from skimage import io import scipy import numpy as np def render_image_as_table(image="work.jpg"): '''outputs a formatted html table that looks like the input image ''' print "render_image_as_table starting on %s" % image img = io.imread(image) table = '\n
\n' for w in range(img.shape[0]): table += '\n\n' for h in range(img.shape[1]): r = img[w,h,0] g = img[w,h,1] b = img[w,h,2] table += '' % (r,g,b) table += '\n' table += '\n
\n
\n\n\n

\n\n\n' print "render_image_as_table returning table for %s" % image return table def render_image_as_table_old(image="work.jpg"): '''outputs a formatted html table that looks like the input image TODO: CAN KILL this just does a lot of extra work to output same as above ''' #image input and orientation print "render_image_as_table starting on %s" % image img = io.imread(image) img = np.fliplr(img) img = scipy.rot90(img,1) width = img.shape[0] height = img.shape[1] #table creation table = '\n
\n' for h in range(height): table += '\n\n' for w in range(width): r = img[w,h,0] g = img[w,h,1] b = img[w,h,2] table += '' % (r,g,b) table += '\n' table += '\n
\n
\n\n\n

\n\n\n' print "render_image_as_table returning table for %s" % image return table def page_as_posted(): header = base.default_header("HTML Table as an Image", "A Study in Style") test_table = render_image_as_table("b.jpg") test_table += render_image_as_table("c.jpg") test_table += render_image_as_table("d.jpg") test_table += render_image_as_table("e.jpg") test_table += render_image_as_table("f.jpg") head_dictionary={'title': "HTML Table as an Image"} footer_text = "I was bored on a winter's day..." body_dictionary = {'header': header, 'main': test_table, 'footer':base.default_footer('
%s
' % footer_text,True,True) } base.base_page(body_dictionary, head_dictionary, sN="table_images.html") def test_page(): '''minimal test page see page_as_posted for full production code as uploaded to Net ''' body_dictionary = {'main': render_image_as_table("work.jpg")} base.base_page(body_dictionary, sN="page_image_rendered_as_table.html") if __name__ == "__main__": print "test page" test_page()