> web-file-viewer.sourceforge.net > scripts

<= Parent directory | Home Directory revision date: 2008/08/11 14:19:39 UTC.
 

Show/Download this file as plain text ]

#!/bin/sh

# mkgallery.sh

# 20030315 PixEye@bigfoot.com	Creation

firstStep=1				# Step to start with
stepNumber=7				# Number of steps
md='/mnr/apn'				# Directory to mount
cmd=`basename $0`			# Command name
usage="Usage: $cmd -h|--help [...]\n"	# Help message:
usage=$usage"\n\tDisplay this help message.\n\n"
usage=$usage"\nUsage: $cmd [-c] [-md <mount_directory>] [-s <step>]"
usage=$usage"\n\t\t\t[<few_keywords_for_the_album>]\n"
usage=$usage"\n\tMake a gallery directory and retrieve pictures from a camera."
usage=$usage"\n\t\t-c copy pictures from the camera instead of moving them."
usage=$usage"\n\t\t-s start at the specified step (default is $firstStep)."
usage=$usage"\n\t\t\tNumber of steps: $stepNumber"
usage=$usage"\n\t\t\tType: '$cmd -s 9 test' to get step actions."
usage=$usage"\n\t\t-md change the directory to mount (default is $md)."
#usage=$usage"\n\t."

if test `uname` != "HP-UX" ; then e="-e" ; fi	# HP-UX echo case

action="mv"
while [ "$#" -ge 1 ] ; do
  case "$1" in
    -c) action="cp" ; shift ;;
    -s) echo "$2"|grep -q ^[0-9][0-9]*$
	if [ "$?" -ne 0 ] ; then
		echo "Invalid start step number!" 1>&2
		echo "It should be an INTEGER between 1 and $stepNumber." 1>&2
		echo "Use -h option for help." 1>&2
		exit 101
	elif [ "$2" -lt 1 -o "$2" -gt "$stepNumber" ] ; then
		echo "Invalid start step number!" 1>&2
		echo "It should be an integer BETWEEN 1 and $stepNumber." 1>&2
		echo "Use -h option for help." 1>&2
		if [ "$2" -lt 1 ] ; then exit 102 ; else echo 1>&2 ; fi
	fi
	firstStep="$2" ; shift 2 || exit $? ;;
    -md) md="cp" ; shift 2 || exit $? ;;
    -h|--help)
	echo $e $usage 1>&2 ; exit 103 ;; 	# Display message help and exit
    *) break ;;
  esac
done

function trim {
	echo $*|sed -e 's/^[     ]\+//' -e 's/[      ]\+$//'
}

title=''
if [ "$#" -gt 0 ] ; then title="$*"
else echo $e "Please give few album keywords: \c" ; read title ; fi
title=`trim $title|sed -e 's/ \+/_/g'`

# Let's start:
step=1


# - create the album directory
echo $e "$cmd: $step/$stepNumber) create the album directory..."
dir=`date +"%Y%m%d"`"_$title"
if [ $firstStep -gt $step ] ; then
  echo "Step $step skipped."
  step=`expr $step + 1`
else
  echo "Directory: $dir"
  mkdir -- "$dir" || exit $?
  
  cd -- "$dir" || exit $?
  step=`expr $step + 1` ; echo $e "Step $step/$stepNumber OK."
fi


# - retreive pictures
echo $e "\n$cmd: $step/$stepNumber) retreive pictures from the camera..."
if [ $firstStep -gt $step ] ; then
  echo "Step $step skipped."
  step=`expr $step + 1`
else
  echo $e "Please SWITCH ON YOUR CAMERA & PRESS ENTER... \c" ; read r
  mount /mnt/apn || exit $?
  "$action" /mnt/apn/dcim/100_fuji/* . || exit $?
  umount /mnt/apn || exit $?
  echo $e "\t***** YOU CAN SWITCH OFF YOUR CAMERA NOW *****"
  step=`expr $step + 1` ; echo $e "Step $step/$stepNumber OK."
fi


# - timestamp picture files
echo $e "\n$cmd: $step/$stepNumber) timestamp picture files..."
if [ $firstStep -gt $step ] ; then
  echo "Step $step skipped."
  step=`expr $step + 1`
else
  snap_ren.sh -n $title *.* || exit $?	# This requires the script: snap_ren.sh
  step=`expr $step + 1` ; echo $e "Step $step/$stepNumber OK."
fi


# - make thumbnails
echo $e "\n$cmd: $step/$stepNumber) make thumbnails..."
maxThumbSize="160x120"
if [ $firstStep -gt $step ] ; then
  echo "Step $step skipped."
  step=`expr $step + 1`
else
  # This requires the other script: mkthumbs.sh
  mkthumbs.sh -g $maxThumbSize -n *.* || exit $?
  step=`expr $step + 1` ; echo $e "Step $step/$stepNumber OK."
fi


# - backup original pictures
echo $e "\n$cmd: $step/$stepNumber) backup original pictures..."
if [ $firstStep -gt $step ] ; then
  echo "Step $step skipped."
  step=`expr $step + 1`
else
  #	This requires the ImageMagick package:
  size=`identify *.*|cut -d' ' -f3|sort -n|tail -1`
  echo "Original picture size: $size."
  mkdir -- "$size" || exit $?
  mv *.* "$size/" || exit $?
  step=`expr $step + 1` ; echo $e "Step $step/$stepNumber OK."
fi


# - rotate pictures if needed
echo $e "\n$cmd: $step/$stepNumber) rotate pictures if needed..."
smallerMaxSize="640x640"
smallerGeom="-geometry $smallerMaxSize"
thumbGeom="-geometry $maxThumbSize"
if [ $firstStep -gt $step ] ; then
  echo "Step $step skipped."
  step=`expr $step + 1`
else
  for f in "$size/"*.* ; do
    f=`basename $f`
    echo $e "Minimizing ($smallerMaxSize) $f... \c"
    convert $smallerGeom "$size/$f" "$f" || exit $?	# Set pictures smaller
    echo OK
  done
  
  for viewer in eeyes ee display gqview xv ; do
    if test -n "`type -p $viewer`" ; then
      for f in *.* ; do
        identify "$f"|cut -d' ' -f-3
        echo $e "Get the top border of the picture and quit the image viewer please."
        echo $e "$viewer .thumbnails/$f \c"
        "$viewer" "$f" || exit $?
  
        echo $e "\nIf you want to rotate this picture, where is the top border?"
        notAnswered=true
        while $notAnswered ; do
	echo $e "[L]eft or [R]ight ([N] or [I] to ignore)? \c" ; read rep
	case "$rep" in
	  r|R|d|D)	convert $smallerGeom -rotate 270	"$size/$f" "$f" || \
		exit $?
	    mogrify -rotate 270 $thumbGeom ".thumbnails/$f" || exit $?
	    notAnswered=false ;;
	  l|L|g|G)	convert $smallerGeom -rotate 90	"$size/$f" "$f" || \
		exit $?
	    mogrify -rotate 90  $thumbGeom ".thumbnails/$f" || exit $?
	    notAnswered=false ;;
	  n|N|i|I|'') notAnswered=false ;;
	esac
        done
      done
      imageViewer=`basename $viewer`
      break
    fi
  done
  step=`expr $step + 1` ; echo $e "Step $step/$stepNumber OK."
fi


# - make symbolic link in the original picture directory
echo $e "\n$cmd: $step/$stepNumber) link original pictures to thumbnails..."
if [ $firstStep -gt $step ] ; then
  echo "Step $step skipped."
  step=`expr $step + 1`
else
  cd "$size" || exit $?
  ln -s ../.thumbnails . || exit $?
  step=`expr $step + 1` ; echo $e "Step $step/$stepNumber OK."
fi


# The end
exit 0		# Normal exit

# Prefs for vim editing:
# vim: tabstop=8 shiftwidth=8 textwidth=80


mkgallery.sh
(5k)

mkthumbs.sh
(1k)

snap_ren.sh
(2k)

web-files-viewer_php.txt
(19k)

wfvgrc_php.txt
(1k)

Powered by Web File Viewer W3C XHTML 1.1 certified W3C CSS valid WFV revision date: 2005/12/04 11:43:26 UTC.