![]() |
Guide to configuring trackmate on Windows using the PS3Eye |
Tuesday, August 11, 2009
Saturday, June 06, 2009
Dynamic Web Displayed Images: Python and PHP
Overview
Dynamic images on the web can be a tad tricky. The general procedure is to write out an image header as opposed to the standard html one. Following that is the raw binary for the image. Below are examples of doing this in Python and PHP.
Python using the PIL library
#!/path/to/python
from PIL import Image, ImageDraw
import sys
im = Image.new("P", (200, 200))
draw = ImageDraw.Draw(im)
draw.rectangle((0, 0) + im.size, fill="blue")
# Any manipulation of the image
print "Content-Type: image/png\r\n"
im.save(sys.stdout, "PNG")
Python Debugging
This is incredibly fragile. I originally tried a solution I found on a mailing list and had to make tons of modification to get it running.
- Wrong content type: The image/type must match with the output
- Not including the python executable path: If the top line is not setup correctly(#!/path/to/python) or is missing, it may run correctly in the command line but fail on the web
- Wrong newline setup: I found I had to have exactly the number of newlines I did, most people show an additional "\r\n", but this broke mine
- sys.stdout.write: This didn't work for me. It shows up fine on the command line, but doesn't work on the Apache webserver I was using. Use print instead.
- PIL not installed: The machine it is running on needs the Python Imaging Library
The bad thing about most of these bugs is that they look just fine on the command line, and only fail when run on a web server.
PHP using the GD library
<?php
$my_img = imagecreate( 200, 200 );
imagecolorallocate( $my_img, 0, 0, 255 );
# Any manipulations of the image
header( "Content-type: image/png" );
imagepng( $my_img );
imagedestroy( $my_img );
?>
PHP Debugging
The only problem I've had with this is GD not being installed properly. Other than that if you can run PHP scripts you shouldn't have issues.
Conclusion
This is a usefull technique but was very hard to find relevant information online, especially for Python. This is a much better solution than saving off pictures and then pushing that to the user like I've seen alot of online.
Monday, March 16, 2009
Gentoo Bugs: Audacious and Timidity
Same as up on my site, just put up here since this blog gets indexed by google more often
=====
So a couple of irritating Gentoo bugs that I recently had to deal with. Posting here and on my old blog, so hopefully anyone with similar problems can get it resolved quicker, since the portage maintainers are often slow.
Audacious DBus Error: Issue
starting Audacious gives the following:
Audacious DBus Error: Fix
Use the following command as root:
Audacious DBus Error: Reason
The music player inexplicably requires a unique id to actually start up. A normal dbus install on Gentoo doesn't create the machine-id file with the id in it.
Timidity++ Service Error: Issue
When trying to start timidity++ you see:
Timidity++ Service Error: Fix
In /etc/init.d/timidity delete the following text:
Timidity++ Service Error: Reason
Emerging timidity failed to give proper privledges to the created Timidity user, so this just makes it run as root (Lazy, I know). You could also try to play with adding user permissions.
Saturday, January 17, 2009
OMGWTFRNG

A somewhat overboard set of tools to generate random numbers.
Uses:
* AES RNG
* Clock Drift
* Atmospheric Data from the web
* /dev/random
and XORs them all together.
A detailed write-up and all the source code can be found on devrand.org