Archive & Timestamp Webcam Images


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/bin/sh
  2.  
  3. function saveCamImage {
  4. wget --quiet --dns-timeout=10 --connect-timeout=10 $1 -O $2
  5. }
  6.  
  7. function applyDatestamp {
  8. echo `date "+%F %H:%M"` | convert $1 -resize 320x240 -type Optimize -quality 70 -bordercolor black -border 20 \
  9. -font Courier -pointsize 17 -fill grey \
  10. -annotate +90+15 "$2" \
  11. -annotate +90+275 '@-' $1 > /dev/null
  12. }
  13.  
  14. function thumbCamImage {
  15. convert $1 -resize 128x96 $2 > /dev/null
  16. }
  17.  
  18. function archiveCam {
  19. imageDate=`date +%F_%H%M`
  20. PROCESS_DIR=$1
  21. CAM_IMAGE_URL=$2
  22. CAM_TITLE=$3
  23.  
  24. if [ -d $PROCESS_DIR ]; then
  25. DIR_STATUS="[`date +%F_%H%M`] $PROCESS_DIR exists, no need to create."
  26. else
  27. DIR_STATUS="[`date +%F_%H%M`] $PROCESS_DIR missing! Creating."
  28. mkdir -p $PROCESS_DIR
  29. fi
  30.  
  31. if [ -d "$PROCESS_DIR/thumbs" ]; then
  32. DIR_STATUS="[`date +%F_%H%M`] $PROCESS_DIR/thumbs exists, no need to create."
  33. else
  34. DIR_STATUS="[`date +%F_%H%M`] $PROCESS_DIR/thumbs missing! Creating."
  35. mkdir -p $PROCESS_DIR/thumbs
  36. fi
  37.  
  38. ### Download new image from cam
  39. CAM_IMAGE="$PROCESS_DIR/$imageDate.jpg"
  40. saveCamImage $CAM_IMAGE_URL $CAM_IMAGE
  41.  
  42. ### Apply timestamp on top
  43. CAM_STAMPED="$CAM_IMAGE.stamped.jpg"
  44. applyDatestamp $CAM_IMAGE $CAM_TITLE
  45.  
  46. ### Cache image
  47. convert -quality 60 $CAM_IMAGE "/var/www/html/cams/cache/$CAM_TITLE.jpg"
  48. convert -resize 320x240 "/var/www/html/cams/cache/$CAM_TITLE.jpg" "/var/www/html/cams/cache/$CAM_TITLE.jpg"
  49.  
  50. }
  51.  
  52. ARCHIVE_DIR="/path/to/cams/archive"
  53. ARCHIVE_DIR_SOMEWHERE="$ARCHIVE_DIR/somewhere/`date +%Y`/`date +%m`/`date +%d`"
  54. URL_SOMEWHERE="http://127.0.0.1/path/to/cam/image.jpg"
  55.  
  56. archiveCam $ARCHIVE_DIR_SOMEWHERE $URL_SOMEWHERE 'CAM FANCY TITLE' &

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.