Wireless Hacks. 1917 IndustrialStrength Tips and Tools [Electronic resources]

Rob Flickenger

نسخه متنی -صفحه : 158/ 34
نمايش فراداده

Hack 15 Photo Blog Automatically with the Nokia 3650

Instantly publish your photos from the road, without even logging in.

To me, digital photography is something of a mixed blessing. The instant gratification of being able to view your photos immediately is many times offset by two small details: you need to have your camera with you and it has to be charged. My camera is much too large and fragile to carry with me all of the time, and I'd hate to have yet another device to keep track of and plug in at night. This means that I end up with lots of "event-style" photos, but relatively few impromptu snapshots of daily life. All too often, by the time I run to grab the camera, the moment has passed, and the perfect photo is gone forever.

A number of manufacturers have realized that there is a device that people habitually carry with them and nearly always keep well charged: their cell phones. Nokia has managed to merge a whole slew of nifty technologies into their 3650 phone, including Bluetooth, GPRS, GSM, and of course, a digital camera. This leads to all sorts of fascinating possibilities. Not only is it simple to upload photos to a laptop using Bluetooth, but the interface for sending photos via email is also dead simple. As if IM spam weren't bad enough, mankind is now developing the ability to spam each other with video.

Rather than throw photo bits at your friends and relatives, it is much more efficient to publish your photo album to a web page, and IM your friends and family the link to it. With a little bit of scripting fu, it is straightforward to have a script that will accept an email and publish it to a web page.

The Code

First, you need to have your script accept email. This is easily done with a procmail recipe. Add this to your .procmailrc on your mail server:

:0 
* ^TO yoursecretaddress@yourdomain.com
| /home/username/bin/phonecam.sh

Of course, change yoursecretaddress@yourdomain.com to the email address that your photo server will use, and fix the path to the following script to point to a real directory. Keep this address private, because any images sent to it will automatically be published! If you're not running procmail on your mail server, consult your friendly neighborhood sysadmin for assistance.

Next, save the following code to a file called phonecam.sh in the directory you specified in your .procmailrc. You can download the original from http://freenetworks.org/~mattw/badsoftware/phonecam/ (this copy has been edited slightly for size). Edit the variables at the top to suit your system.

#!/bin/sh
#phonecam.sh
filepath="/home/username/publicl/phonecam"
imgdir="img"
html=l"
time=`date +%s`
baseref="http://yoursite.com/~username/phonecam"
title="Phonecam v.3"
arcdate=`date +%D |sed '''s/1//./g'''`
perpage="16"
umask 062
if [ ! -f $filepath/count ]; then
echo "0" > $filepath/count
fi
if [ ! -f $filepath/arc.txt ]; then 
touch $filepath/arc.txt
fi
if [ ! -d $filepath/archive ]; then 
mkdir $filepath/archive
fi
if [ ! -d $filepath/l ]; then 
mkdir $filepath/l
fi
if [ ! -d $filepath/$imgdir ]; then 
mkdir $filepath/$imgdir
fi
count=`head -1 $filepath/count`
mkdir ~/.$$
cd ~/.$$
munpack
for i in *.jpg; do
a=`basename $i .jpg`
mv $i $filepath/$imgdir/$time.jpg
convert -resize 320x240 1
$filepath/$imgdir/$time.jpg $filepath/$imgdir/$time.thumb.jpg
convert -resize 150x90 $filepath/$imgdir/$time.jpg $filepath/latest.jpg
# make the new page 
cat $filepath/new.txt > $filepath/new.tmp
echo "<a href=1"$baseref/l/$timel1"> 
<img src=1"$baseref/$imgdir/$time.thumb.jpg1"
width=1"3201" height=1"2401" border=0></a>" 
> $filepath/new.txt
cat $filepath/new.tmp >> $filepath/new.txt
rm $filepath/new.tmp
# make the individual photo page 
echo "<l>
<head><title>$title</title></head><body bgcolor=000000>
<center><img src=1"$baseref/$imgdir/$time.jpg1" border=1></center><p>" 
> $filepath/l/$timel
cat $a.desc >> $filepath/l/$timel
echo "</body><l>" >> $filepath/l/$timel
count=`expr $count + 1`
done
echo $count > $filepath/count
if [ $count = 1 ]; then 
echo "There is 1 image in the queue" > $filepath/notify
else
echo "There are $count images in the queue" > $filepath/notify
fi
if [ $count = $perpage ]; then 
echo "<l><head><title>$title</title></head><body bgcolor=000000><center>" 
> $filepath/archive/$timel
cat $filepath/index.txt >> $filepath/archive/$timel
cp $filepath/new.txt $filepath/index.txt
rm $filepath/count
rm $filepath/new.txt
cat $filepath/arc.txt > $filepath/arc.tmp
echo "<li><a href=1"$baseref/archive/$timel1">$arcdate</a></li>" 
>> $filepath/arcn.txt
cat $filepath/arc.tmp >> $filepath/arcn.txt
rm $filepath/arc.tmp
mv $filepath/arcn.txt $filepath/arc.txt
echo "There are no new images in the queue" > $filepath/notify
fi
rm -rf ~/.$$

In addition to this script, you need a copy of munpack (to decode mime attachments) and convert (part of the Image Magick suite). These tools are available in all standard Linux distributions.

Finally, create an index.l file in your web server's document root that contains a line like this:

<!--#include virtual="index.txt"-->

For a more advanced example of what you can do with the index.l file, take a look at the example available at http://freenetworks.org/~mattw/badsoftware/phonecam/index.l.txt.

Running the Hack

With all of the above in place, simply send a photo via email to your secret photo email address. The script automatically decodes the email, creates a thumbnail, and puts the photo into a queue. When the queue accumulates perpage photos, it rotates in the page full of photos, and moves the old page into an archive. You can always access the latest photo at http://server/~yourname/phonecam/latest.jpg, and see the entire pending queue at http://server/~yourname/phonecam/new.txt. The script manages the queue and archives without any intervention, and will even post an optional description of your photos. Just add a text body to the email and it will be inserted as the photo's description.

This script could probably be simplified and improved, but this simple shell script should run on just about any server. It creates a simple but powerful archiving web interface that is easily integrated into a weblog or other existing web page. And it pushes the instant gratification of digital photos even further, into the realm of instant publication.

See Also

Matt Westervelt's phonecam project (http://freenetworks.org/~mattw/badsoftware/phonecam/)

Image Magick (http://www.imagemagick.org/)