#!/bin/bash
# reduce500

# change the size as desired

# uses convert from the ImageMagick  suite to reduce the size
# of all the *.png and *.png files to a sample size of 
# 500 pixels x 500 pixels. 
#  add _500 to the name so that know reduced
#  keeps original format (jpg or png)
#  original appears in file list, but I also create and copy to ./ORIGINALS

# eliminate the extensions with capital letters
# no loop for rename
rename  .PNG  .png  *.PNG
rename  .JPG  .jpg  *.JPG

# backup copy
mkdir ./ORIGINALS/
cp *.png ./ORIGINALS/
cp *.jpg./ORIGINALS/

   
# trick to add 500   first rename to *500.png ===) .png.500.png
# note that the name of "img" still has ".png" in it, I eliminate the double "png" below
for img in `ls *.png`
do
   convert -sample 500x500     $img       $img.500.png
done

#same for .jpg
for img in `ls *.jpg`
do
   convert -sample 500x500     $img       $img.500.jpg
done

# now eliminate the unwanted .png500.png & jpg
   rename .png.500.png   _500.png  *500.png
   rename .jpg.500.jpg   _500.jpg  *500.jpg
   
# as a check,  we list the files, original appears too
ls