#!/bin/bash


echo "1 ---------------- Convert [subject_images] to webp -----------------"
IMAGES=`find images/subjects -type f \( -iname \*.jpg -o -iname \*.bmp -o -iname \*.tiff  \)`   # Use the -o flag between different parameters.
webpQuality=100
for image in $IMAGES; do
	if [ ! -f ${image%%.*}.webp ]; then
		cwebp -q $webpQuality $image -o ${image%%.*}.webp
	fi
done

# 
# 
# echo "2 --------Make table of content file (00.TOC.txt) in each folder-------------"
# SUBJECTS=`ls -d images/subjects/*`
# for subject in $SUBJECTS; do
# 	echo $subject
# 	find $subject -iname *.webp -printf "%f\n" > $subject/00.TOC.txt
# done
# 
# 
# echo "3 ---------------- Convert background images to webp -----------------"
# IMAGES=`find images/background -type f \( -iname \*.jpg -o -iname \*.bmp -o -iname \*.tiff  \)`   # Use the -o flag between different parameters.
# webpQuality=50
# for image in $IMAGES; do
# 	cwebp -q $webpQuality $image -o ${image%%.*}.webp
# done
# 
# 
# echo "4 ---------------- Convert Tumbnail images to webp -----------------"
# IMAGES=`find images/tumbnail -type f \( -iname \*.jpg -o -iname \*.bmp -o -iname \*.tiff  \)`   # Use the -o flag between different parameters.
# webpQuality=20
# for image in $IMAGES; do
# 	cwebp  -resize 300 0 -q $webpQuality $image -o ${image%%.*}.webp
# done
# 
# 
# echo "5 --------Make table of content file (00.TOC.tmp) of Tumbnails-------------"
# find images/tumbnail -iname *.webp -printf "%f\n" > $subject/00.TOC.tmp
# 
# echo "Please edit the file images/tumbnail/00.TOC.tmp "
# echo "Add the subject names in the second tab delimted column (identical to subject folders)"
# echo "SAVE AS images/tumbnail/00.TOC.txt"

 