#!/bin/sh

 # Juar rhw rotation fo rotn* images

# from 1600x1200 jpegs, 1024x768 ones, 30% ones and 15% ones are created,
# with symlinked .xvpics directories

# Jenik Hollan, N. Copernicus Observatory and Planetarium in Brno, April 2002

# An alternative for ** images, around 0.3 MB ones.

# to make the index files, sed is to be installed in unix (a must anyway)

#  date_hp315_jpgs
 
if [ -d fit ]
 then 
  if [ -d rotn ]
  then
   cd rotn
#   date_hp315_jpgs
   for F in *.jpg 
    do convert -rotate -90 -geometry 48% -quality 75 $F ../fit/$F
    touch -r $F ../fit/$F 
   done
   cd ..
  fi 
  if [ -d rotnr ]
  then
   cd rotnr
#   date_hp315_jpgs
   for F in *.jpg 
    do convert -rotate 90 -geometry 48% -quality 75 $F ../fit/$F
    touch -r $F ../fit/$F 
   done
   cd ..
  fi 
  cd fit
  index_thumb
#  the images are still large, so index with thumbnails is created  
 else
  cd fit 
fi

if [ -d third ]
 then
  cd ..
  if [ -d rotn ]
  then
   cd rotn
   for F in *.jpg 
    do convert -rotate -90 -geometry 30% -quality 80 $F ../fit/third/$F
    touch -r $F ../fit/third/$F 
   done
   cd ..
  fi
  if [ -d rotnr ]
  then
   cd rotnr
   for F in *.jpg 
    do convert -rotate 90 -geometry 30% -quality 80 $F ../fit/third/$F
    touch -r $F ../fit/third/$F 
   done
   cd ..
  fi
  cd fit/third
  index_tab
#  index is created with dates and filenames at the right, as a table 
fi

if [ -d sixth ]
 then
  cd ../..
  if [ -d rotn ]
  then
  cd rotn
  for F in *.jpg 
  do 
   cd ../fit/third
   convert -geometry 50% -quality 70 $F sixth/$F
   touch -r $F sixth/$F 
#  this gives the smaller file the original timestamp
   cd ../../rotn
  done
  cd ..
  fi
  if [ -d rotnr ]
  then
  cd rotnr
 for F in *.jpg 
  do 
   cd ../fit/third
   convert -geometry 50% -quality 70 $F sixth/$F
   touch -r $F sixth/$F 
#  this gives the smaller file the original timestamp
   cd ../../rotnr
  done
  cd ..
  fi
  cd fit/third/sixth
  index_plain
#  index with just all images themselves is created, simply filling the page   
 else
  cd sixth 
fi

if [ -d thumb ]
 then
  cd ../../..
  if [ -d rotn ]
  then
  cd rotn
  for F in *.jpg 
  do 
   cd ../fit/third/sixth
   convert -geometry 60% $F thumb/$F
   touch -r $F thumb/$F 
   cd ../../../rotn
  done
  cd ..
  fi
  if [ -d rotnr ]
  then
  cd rotnr
  for F in *.jpg 
  do 
   cd ../fit/third/sixth
   convert -geometry 60% $F thumb/$F
   touch -r $F thumb/$F 
   cd ../../../rotnr
  done
  cd ..
  fi
  cd fit/third/sixth/thumb
 # ln -s ../.xvpics ./
  index_plain
#  index with just all images themselves is created, simply filling the page   
 else
  cd thumb
fi

cd ../../../..

if [ -d .xvpics ]
 then
  if [ -d rotn ]
  then
   cd rotn
   for F in *.jpg 
    do convert -rotate -90 -quality 93 $F ../$F
    touch -r $F ../$F 
   done
   cd ..
  fi 
  if [ -d rotnr ]
  then
   cd rotnr
   for F in *.jpg 
    do convert -rotate 90 -quality 93 $F ../$F
    touch -r $F ../$F 
   done
   cd ..
  fi 
  index_thumb
#  the images are very large, so index with just thumbnails is created  
  if [ ! -a list.htm ]
   then 
# renaming the output of index_thumb back to list.htm
   mv index.htm list.htm
  fi
  if [ ! -d fullsize ]
   then
    mkdir fullsize
    cd fullsize
    ln -s ../*.jpg ./
    cd ..
  fi
fi

#if [ (du -sS | sed "s/[[:blank:]]\(.*\)//")  \
#    < (df ./ | sed  -n "2 s/ \+/ /gp" | cut -d ' ' -f 4) ] 
# then
#  ls 
#fi

cd fit/third

zgv 
# here the user is assumed to press u to create thumbnails 
# and then exit sometimes later
