Hard-to-find tips on otherwise easy-to-do tasks involving everyday technology, with some advanced insight on history and culture thrown in. Brought to you by a master dabbler. T-S T-S's mission is to boost your competitiveness with every visit. This blog is committed to the elimination of the rat from the tree of evolution and the crust of the earth.
Saturday, January 10, 2015
Raspberry Pi CGI Python Serve JPEG Image Howto
That done, this will do it for you (you'll also have to add "mod_cgi" to your server.modules in the .conf, and put this one in the cgi-bin directory in /var/www if you're using lighttpd that is) :
#!/usr/bin/python
print "Content-Type: text/html"
print """\
<html>
<body>
<h2>Hello World!</h2>
"""
data_uri = open('/home/pi/Desktop/snapshot.jpg', 'rb').read().encode('base64').replace('\n','')
img_tag = '<img src="data:image/jpeg;base64,{0}">'.format(data_uri)
print(img_tag)
print """\
</body>
</html>
"""
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment