# !/bin/bash
#
# autor: Kamil Porembinski
# mail: paszczak [at] thecamels.org
# www: www.thecamels.org
#
##################################################################################
# Execute in a directory with JPG files.
# The script requires the tools convert from ImageMagick.
#
##################################################################################
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
##################################################################################

# Configuration:
size="2048x2048" #Size of images

# Create folder for miniatures
mkdir min

# Change big characters to small
for name in *.JPG
do
	mv -f $name `echo $name | tr -d _ | tr '[A-Z]' '[a-z]'`
done

# Find and count number of image files
files=(`find . -maxdepth 1 -iregex ".*\.jpg$" -type f -print | sort -f`)

# Remember file names into a $filenames
for (( i=0; i < ${#files[@]}; i++ ));
do
	filenames[$i]=`basename "${files[$i]}" | sed s/\ /_/g`;
done

for (( i=0; i < ${#filenames[@]}; i++ ));
do
	echo -e "Resizing ${filenames[$i]}\t\t[`expr $i + 1`/${#filenames[@]}]"
	convert -scale $size ${filenames[$i]} min/${filenames[$i]}
done
