Return to Snippet

Revision: 15281
at June 30, 2009 01:38 by cshaiku


Initial Code
#!/bin/sh

function saveCamImage {
  wget --quiet --dns-timeout=10 --connect-timeout=10 $1 -O $2
}

function applyDatestamp {
  echo `date "+%F %H:%M"` | convert $1 -resize 320x240 -type Optimize -quality 70 -bordercolor black -border 20 \
  -font Courier -pointsize 17 -fill grey \
  -annotate +90+15 "$2" \
  -annotate +90+275 '@-' $1 > /dev/null
}

function thumbCamImage {
  convert $1 -resize 128x96 $2 > /dev/null
}

function archiveCam {
  imageDate=`date +%F_%H%M`
  PROCESS_DIR=$1
  CAM_IMAGE_URL=$2
  CAM_TITLE=$3

  if [ -d $PROCESS_DIR ]; then
    DIR_STATUS="[`date +%F_%H%M`] $PROCESS_DIR exists, no need to create."
  else
    DIR_STATUS="[`date +%F_%H%M`] $PROCESS_DIR missing! Creating."
    mkdir -p $PROCESS_DIR
  fi

  if [ -d "$PROCESS_DIR/thumbs" ]; then
    DIR_STATUS="[`date +%F_%H%M`] $PROCESS_DIR/thumbs exists, no need to create."
  else
    DIR_STATUS="[`date +%F_%H%M`] $PROCESS_DIR/thumbs missing! Creating."
    mkdir -p $PROCESS_DIR/thumbs
  fi

### Download new image from cam
  CAM_IMAGE="$PROCESS_DIR/$imageDate.jpg"
  saveCamImage $CAM_IMAGE_URL $CAM_IMAGE

### Apply timestamp on top
  CAM_STAMPED="$CAM_IMAGE.stamped.jpg"
  applyDatestamp $CAM_IMAGE $CAM_TITLE

### Cache image
  convert -quality 60 $CAM_IMAGE "/var/www/html/cams/cache/$CAM_TITLE.jpg"
  convert -resize 320x240 "/var/www/html/cams/cache/$CAM_TITLE.jpg" "/var/www/html/cams/cache/$CAM_TITLE.jpg"

}

ARCHIVE_DIR="/path/to/cams/archive"
ARCHIVE_DIR_SOMEWHERE="$ARCHIVE_DIR/somewhere/`date +%Y`/`date +%m`/`date +%d`"
URL_SOMEWHERE="http://127.0.0.1/path/to/cam/image.jpg"

archiveCam  $ARCHIVE_DIR_SOMEWHERE  $URL_SOMEWHERE  'CAM FANCY TITLE'  &

Initial URL
http://code.cshaiku.com/code_bash_archive_webcams.php

Initial Description

                                

Initial Title
Archive & Timestamp Webcam Images

Initial Tags
images, cache

Initial Language
Bash