Running Imagesnap From a PHP Script.

As part of a project I started a month or so ago I wanted to be able to take a photo from the iSight camera in current iMacs from an SSH terminal. To do this I came across imagesnap.

This satisfied my problem for a little while, but before long I wanted more functionality. This led me to creating a PHP script to call imagesnap and thus give me a web interface to the iSight camera. It all seemed to be working, my form was submitting and there were no PHP errors being thrown, but there was no file being created. I checked permissions, everything seemed fine. I SSHed in and ran imagesnap manually, everything worked fine. I googled for days but couldn’t find anything. I even scoured the source code of imagesnap to try to get some insight but to no avail.

Eventually I ran my PHP script from an SSH terminal to try to produce some sort of error and to my surprise everything worked fine, but back in the browser – nothing.

The next piece of the puzzle came whilst playing around imagesnap itself, apparently when it is executed as anyone but a regular user it does not find any devices. This meant when apache was calling the PHP who in turn was calling imagesnap, it was getting executed as the apache user and couldn’t find any devices to take the photo with. The fix was call the imagesnap as a regular user. The easiest way to do this is to set its owner to be a regular user and then set permissions to be set user ID on execution using chmod.

chown username imagesnap
chmod 4755 imagesnap

Hopefully this will be useful for anyone else trying something similar.

For those interested I still have a few things to fix up before posting this app.

Leave a Reply


Blog Categories

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Latest Posts

Blog Feed’s and Share

  • rss
  • facebook
  • twitter
Complex Compulsions

© 2009-2010 Jeremy Worboys.

Tweaked from Picco by Iamilkay & Krones.