Prototyping 14 May 2013

From XPUB & Lens-Based wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Continuing with the browser code...

Letterwalk

Pixelwalk

#!/usr/bin/python
#-*- coding:utf-8 -*-

import urllib2, cgi, cgitb; cgitb.enable()
from PIL import Image
print 'content-type: text/html'
print

print '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>'

print '''
<script>
$(document).ready(function(){
   $("#image").mousemove(function(e){
   		var ypos=e.pageY;
   		var xpos=e.pageX;
   		window.location = "?x="+xpos+"&y="+ypos;
   		console.log(xpos);
   		console.log(ypos);
      	$("#status").html(e.pageX +", "+ e.pageY);
   }); 
})
</script>
'''

q = cgi.FieldStorage()
x = int(q.getvalue("x",0))
y = int(q.getvalue("y",0))

print x,y

imgpath="../yes.jpg"
i = Image.open(imgpath)
print i.size
w,h=i.size
r,g,b = i.getpixel((x,y))
print i.getpixel((200,200))
colorvalue=i.getpixel((200,200))

print '''
<body style="background:grey;">
<div id="image" style="width:{0}px; height:{1}px; background-color:rgb({2},{3},{4});">	
</div>
'''.format(w,h,r,g,b)