Prototyping 14 May 2013: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "Continuing with the browser code... Pixelwalker")
 
No edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Continuing with the browser code...
Continuing with the browser code...


Pixelwalker
[[Letterwalk]]
 
== Pixelwalk ==
 
 
<source lang=python>
#!/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) 
</source>

Latest revision as of 13:56, 14 May 2013

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)