|
|
4c79b5 |
#!/bin/bash
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# groupByFormats.sh -- This function provides post-rendering action
|
|
|
4c79b5 |
# used to group images by format. This function create a directory
|
|
|
4c79b5 |
# for for the image format and move the image file inside it. For
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# For this function to work correctly, you need to specify which formats you
|
|
|
4c79b5 |
# want to group. This is done in the post-rendering ACTIONS array inside the
|
|
|
4c79b5 |
# appropriate render.conf.sh script.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# file for each png file and will group them all by its format, inside
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# ppm, xpm, tif).
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# ACTIONS[0]="renderFormats: jpg, ppm, xpm, tif"
|
|
|
4c79b5 |
# ACTIONS[1]="groupByFormat: png, jpg, ppm, xpm, tif"
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# groupByFormat function is generally used with renderFormats function. Both
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# Copyright (C) 2009-2010 Alain Reguera Delgado
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# This program is free software; you can redistribute it and/or modify
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# General Public License for more details.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# along with this program; if not, write to the Free Software
|
|
|
4c79b5 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
4c79b5 |
# USA.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
4c79b5 |
# $Id: render_doIdentityImageGroupBy.sh 56 2010-09-17 11:07:26Z al $
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function groupByFormat {
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Get absolute path of PNG image file.
|
|
|
4c79b5 |
local FILE="$1"
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Get image formats.
|
|
|
4c79b5 |
local FORMATS=$(echo "$2" | cut -d: -f2-)
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Sanitize image formats.
|
|
|
4c79b5 |
FORMATS=$(echo "${FORMATS}" \
|
|
|
4c79b5 |
| sed -r 's!^ *!!g' \
|
|
|
4c79b5 |
| sed -r 's!( |:|,|;) *! !g' \
|
|
|
4c79b5 |
| sed -r 's! *$!!g')
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Check image formats.
|
|
|
4c79b5 |
if [ "$FORMATS" != "" ];then
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Loop through image formats and do group by format.
|
|
|
4c79b5 |
for FORMAT in $FORMATS;do
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Redifine file path to add format directory
|
|
|
4c79b5 |
local SOURCE=${FILE}.${FORMAT}
|
|
|
4c79b5 |
local TARGET=$(dirname $FILE)/${FORMAT}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if [ ! -d $TARGET ];then
|
|
|
4c79b5 |
mkdir $TARGET
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Redifine file path to add file and its format.
|
|
|
4c79b5 |
TARGET=${TARGET}/$(basename $FILE).${FORMAT}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
echo "Moved to: $TARGET"
|
|
|
4c79b5 |
mv ${SOURCE} ${TARGET}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
done
|
|
|
4c79b5 |
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|