#!/bin/csh
# Compression of original full-size images in "archives" directory
#      to reduced-size framed images and storing them in a zip-file compimag.zip
########### ONLY IN ONE PARTICULAR SUBDIRECTORY #########
set year=1999
set roll=97
########### EDIT THE ABOVE LINES! ###########
#   Files comppart, compimag.bat and compimag.bc should be copied to "archives" directory,
#      then comppart is executed
cd $HOME/public_html/pictures/archives
rm -f compimag.zip
chmod 700 compimag.bat
find ./$year/$roll/jpeg \( -name "[0-9][0-9].jpg" -o -name "000.jpg" \) \
-exec cp {} tmp.jpg \; \
-exec compimag.bat \; \
-exec cp tmp1.jpg {} \; \
-exec zip -0 compimag {} \; \
-exec cp tmp.jpg {} \;
#
mv compimag.zip compress
cd compress
unzip compimag
rm -f compimag.zip
#mkdir -p $HOME/temp/$year/$roll
#zip -j0 $HOME/temp/$year/$roll/newcomp $year/$roll/jpeg/*
#zip -j0 $HOME/temp/$year/$roll/newpic ../$year/$roll/jpeg/*
# Printing a list of picture files and counting
cd $HOME/public_html/pictures/archives/compress
chmod 755 tmpsslis.cgi
tmpsslis.cgi
find $year/$roll/jpeg \( -name "[0-9][0-9].jpg" -o -name "000.jpg" \) \
 -exec ls {} \; -exec convert -geometry 1x1 {} tmp.gif \; \
 -exec convert tmp.gif tmp.histogram \; \
 -exec sed -n '/  1  /p' tmp.histogram \; >> colors.dat
# Zipping
cd $HOME/public_html
zip -0 $HOME/temp/pic$roll pictures/archives/$year/$roll/jpeg/*.jpg pictures/archives/compress/$year/$roll/jpeg/*.jpg pictures/archives/compress/tmpsscou.txt pictures/archives/compress/colors.dat
#
# Content of compimag.bat:
#
# imginfo tmp.jpg noimage >img.txt
# sed -ne 's/^.*RGB /a=/p' img.txt | sed -e 's/x/; b=/' -e 's/)/;/' >img.bc
# bc img.bc compimag.bc >img.bat
# chmod 700 img.bat
# img.bat
#
#
# Content of compimag.bc:
#
# n=(a<b);
# m=n*a+(1-n)*b;
# i=(1-2*n)*(a-b);
# i=i/2;
# j=(1-n)*i;
# k=n*i;
# print "#!/bin/csh\n"
# print "set a=",m,"x",m,"+",j,"+",k,"\n"
# print "convert -crop $a -quality 30 -geometry 360x360 -raise 6 -frame 8\\\n"
# print " -normalize tmp.jpg tmp1.jpg\n"
# quit
