#!/bin/sh

# 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

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

 
if [ ! -a fit ]
 then
  mkdir fit
  for F in *.jpg 
   do convert -geometry 64% -quality 95 $F fit/$F
   touch -r $F fit/$F 
  done
  if [ -d rot ]
  then
   cd rot
   for F in *.jpg 
    do convert -rotate -90 -geometry 48% -quality 95 $F ../fit/$F
    touch -r $F ../fit/$F 
   done
   cd ..
  fi 
  cd fit
  mkdir .xvpics
  index_thumb
#  the images are still large, so index with thumbnails is created  
 else
  cd fit 
fi

if [ ! -a third ]
 then
  mkdir third
  for F in *.jpg 
  do convert -geometry 30% -quality 90 ../$F third/$F
  touch -r $F third/$F 
#  this gives the smaller file the original timestamp
  done
  if [ -d rot ]
  then
   cd ../rot
   for F in *.jpg 
    do convert -rotate -90 -geometry 30% -quality 90 $F ../fit/third/$F
    touch -r $F ../fit/third/$F 
   done
   cd ../fit
  fi 
  cd third
  ln -s ../.xvpics ./
  index_tab
#  index is created with dates and filenames at the right, as a table 
 else
  cd third 
fi

if [ ! -a sixth ]
 then
  mkdir sixth
  for F in *.jpg 
  do convert -geometry 50% -quality 80 $F sixth/$F
   touch -r $F sixth/$F 
#  this gives the smaller file the original timestamp
  done
  cd sixth
  ln -s ../.xvpics ./
  index_plain
#  index with just all images themselves is created, simply filling the page   
 else
  cd sixth 
fi

cd ../../..

if [ ! -a .xvpics ]
 then
  ln -s fit/.xvpics .xvpics
  if [ -d rot ]
  then
   cd rot
   for F in *.jpg 
    do convert -rotate -90 -quality 95 $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 fullsize_i ]
   then
    mkdir fullsize_i
   if [ ! -a list.htm ] 
    then 
     mv index.htm fullsize_i
   fi     
   cd fullsize_i
   ln -s ../*.jpg ./
   cd ..
  fi
  if [ ! -a fullsize ]
   then
    mkdir fullsize
    cd fullsize
    ln -s ../*.jpg ./
    cd ..
  fi
fi

cd fit/third

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