Wireless Hacks Free Open Book

Wireless Hacks

Previous Section Next Section

Hack 15 Photo Blog Automatically with the Nokia 3650

figs/expert.giffigs/hack15.gif

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/public_html/phonecam"
imgdir="img"
html="html"
time=`date +%s`
baseref="http://yoursite.com/~username/phonecam"
title="Phonecam v.3"
arcdate=`date +%D |sed '''s/\//./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/$html ]; then 
  mkdir $filepath/$html
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 \
    $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=\"$baseref/$html/$time.html\"> 
    <img src=\"$baseref/$imgdir/$time.thumb.jpg\"
    width=\"320\" height=\"240\" border=0></a>" 
      > $filepath/new.txt

  cat $filepath/new.tmp >> $filepath/new.txt
  rm $filepath/new.tmp

  # make the individual photo page 
  echo "<html>
  <head><title>$title</title></head><body bgcolor=000000>
  <center><img src=\"$baseref/$imgdir/$time.jpg\" border=1></center><p>" 
    > $filepath/$html/$time.html

  cat $a.desc >> $filepath/$html/$time.html

  echo "</body></html>" >> $filepath/$html/$time.html

  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 "<html><head><title>$title</title></head><body bgcolor=000000><center>" 
    > $filepath/archive/$time.html

  cat $filepath/index.txt >> $filepath/archive/$time.html
  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=\"$baseref/archive/$time.html\">$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.shtml 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.shtml file, take a look at the example available at http://freenetworks.org/~mattw/badsoftware/phonecam/index.shtml.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

    Previous Section Next Section
    Index: [SYMBOL][A][B][C][D][E][F][G][H][I][J][L][M][N][O][P][Q][R][S][T][U][V][W][X][Z]


         Main Menu
    Main Page
    Table of content
    Copyright
    Credits
    Foreword
    Preface
    Chapter 1. The Standards
    Chapter 2. Bluetooth and Mobile Data
    2.1 Hacks #13-19
    Hack 13 Remote Control OS X with a Sony Ericsson Phone
    Hack 14 SMS with a Real Keyboard
    Hack 15 Photo Blog Automatically with the Nokia 3650
    Hack 16 Using Bluetooth with Linux
    Hack 17 Bluetooth to GPRS in Linux
    Hack 18 Bluetooth File Transfers in Linux
    Hack 19 Controlling XMMS with Bluetooth
    Chapter 3. Network Monitoring
    Chapter 4. Hardware Hacks
    Chapter 5. Do-It-Yourself Antennas
    Chapter 6. Long Distance Links
    Chapter 7. Wireless Security
    Appendix A. Deep Dish Parabolic Reflector Template
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele