A client operates a simple Web-accessible camera (aka "netcam", "Internet camera" and "ipcam") - a D-Link DCS-G900 - which periodically uploads via FTP an image to a hosting account. The first task was to get the camera online for static images (via FTP), live images (via Java) and to access the camera itself from anywhere (extensively covered in "Extracting dynamic IP from China"). The second task builds upon the data output of the first one and requests for images to be stored in a gallery style for a number of days and to archive even more days in a compressed file. All must be kept as simple as possible in order to support browser platforms ranging from desktops to mobile phones.

Static image
The static image was uploaded in the first task every 60 seconds and the new upload would replace the previous one, thus recycling itself. For the second task, this method won't work as a gallery and archive must be kept for a certain time. Steps taken to store and recycle the images:

  1. Create 3 folders (today, yesterday, 2 days ago)
  2. Configure the camera to upload the images
    - named in datetime format (20071015175725)
    - in the today folder
  3. Create a server script as shown below. The script moves expiring images around the folders, deletes old ones and creates and deletes the weekly archives.
  4. Create a cronjob calling the script daily at midnight.

Script
The script is the main part of this entire task. Without it, the server would eventually be full of images uploaded by the camera as they don't "die of natural cause" and neither would the archive be created.

There's probably a more elegant way to achive the same result, but I prefer to keep it simple and easy to follow and understand.

  • find /CamCN01/Backup/* -mtime +7 -exec rm {} ;
    Delete all daily archive files older than 7 days.
  • tar -czf /CamCN01/Backup/CamCN01_$(date '+%Y%m%d').tar.gz /CamCN01/*.jpg
    Create today's archive named such as "CamCN01_20071015.tar.gz".
  • rm -rf /CamCN01/2DaysAgo/*
    Delete all images from 2 days ago.
  • rm -rf /qdig-files/converted-images/CamCN01/*
    Delete all gallery thumbnails.
  • mv /CamCN01/Yesterday/* /CamCN01/2DaysAgo/
    Move yesterday's images to the folder of 2 days ago.
  • mv /CamCN01/*.jpg /CamCN01/Yesterday/
    Move today's images to the folder of yesterday.

Gallery
The gallery must show single-image pages, an album index of file names and a separate one for thumbnails. Thumbnails must be generated automatically but it's ok if that is done the moment they are called for the first time.

Quick Digital Image Gallery (Qdig) is suitable for this job description. It's simple and small such as it only consists of 4 files and doesn't use a database, and is totally configurable. I haven't come across anything which can't be modified.

Live image
The live image - a feed accessible via a Java applet - remains unchanged.