Donnerstag, 11. September 2014

script improvements: correct naming for captured images

for the webcam gallery the images shall be tagged with a naming convetion like hhmm_xx.jpg
xx varinats are:
hu = huge (original size, for klick&zoom-view in gallery)
la = large (smaller size, for direct view in gallery)
sm = small (small size, for thumbnail view in gallery)

And the photos shall be captured each 10 minutes.
The images shall have straight minute format.

And last but not least the images shall be placed in a directory-structure like /year/month/day/

Example: the image has been shot at 15:36h. DSCF2345.jpg was downloaded form the cam, and renamed by gphoto2 to webcam.jpg.
Then by imagemagick-command 'convert' the following images will be created:
1500_hu.jpg (original)
1500_la.jpg (reduced size 50% from original)
1500_sm.jpg (reduced size 20% from original)
All 3 photos will be uploaded by FTP in the correct folder.
The date-meta-data of the original photo 'webcam.jpg' has been taken into account to create the correct directory, and place the photos correctly.

The whole shell-script with the actual improvements:


#!/bin/bash

host='HOSTNAME'
USER='USERNAME'
PASS='PASSWORD'

rm *.jpg

while true
do
/usr/bin/gphoto2 --capture-image-and-download --filename "webcam.jpg"

imgname="webcam.jpg"
year=`date --reference $imgname +%Y`
month=`date --reference $imgname +%m`
day=`date --reference $imgname +%d`
hour=`date --reference $imgname +%H`
minute=`date --reference $imgname +%M`
mom=`date --reference $imgname +%H`
min=`date --reference $imgname +%M`

# show only full 10min
let min=$min/10*10
[ "$min" = "0" ] && min="00"
mom="${mom}$min"

mv $imgname $mom"_hu".jpg
convert $mom"_hu".jpg -resize 20% $mom"_sm".jpg
convert $mom"_hu".jpg -resize 50% $mom"_la".jpg

ftp -n -v $host <<EOT
ascii
user $USER $PASS
prompt
mkdir /webcamgallerydir/$year
mkdir /webcamgallerydir/$year/$month
mkdir /webcamgallerydir/$year/$month/$day
cd /webcamgallerydir/$year/$month/$day
put $mom"_hu".jpg
put $mom"_la".jpg
put $mom"_sm".jpg
bye
EOT
rm *.jpg
echo wait 10 minutes
sleep 600
done

Keine Kommentare:

Kommentar veröffentlichen