|
|
1d2b07 |
#!/bin/bash
|
|
|
1d2b07 |
#
|
|
|
1d2b07 |
# conf_doBaseActions.sh -- This function standardizes base actions
|
|
|
1d2b07 |
# related to image production through configuration files.
|
|
|
1d2b07 |
#
|
|
|
1d2b07 |
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
|
|
|
1d2b07 |
#
|
|
|
1d2b07 |
# This program is free software; you can redistribute it and/or modify
|
|
|
1d2b07 |
# it under the terms of the GNU General Public License as published by
|
|
|
1d2b07 |
# the Free Software Foundation; either version 2 of the License, or (at
|
|
|
1d2b07 |
# your option) any later version.
|
|
|
1d2b07 |
#
|
|
|
1d2b07 |
# This program is distributed in the hope that it will be useful, but
|
|
|
1d2b07 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
1d2b07 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
1d2b07 |
# General Public License for more details.
|
|
|
1d2b07 |
#
|
|
|
1d2b07 |
# You should have received a copy of the GNU General Public License
|
|
|
1d2b07 |
# along with this program; if not, write to the Free Software
|
|
|
1d2b07 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
1d2b07 |
#
|
|
|
1d2b07 |
# ----------------------------------------------------------------------
|
|
|
1d2b07 |
# $Id$
|
|
|
1d2b07 |
# ----------------------------------------------------------------------
|
|
|
1d2b07 |
|
|
|
1d2b07 |
function conf_doBaseActions {
|
|
|
1d2b07 |
|
|
|
1d2b07 |
local COUNTER=0
|
|
|
9b5d35 |
local EXPORTID="CENTOSARTWORK"
|
|
|
1d2b07 |
local -a MODEL_INSTANCES
|
|
|
9b5d35 |
local -a IMAGE_COMMANDS
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Define absolute path to output location. This is the location
|
|
|
1d2b07 |
# inside the working copy all images will be stored in.
|
|
|
1d2b07 |
local OUTPUT=${OUTPUT}/${FGCOLOR}/${BGCOLOR}/${HEIGHT}/${FILENAME}
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Define which command will be used to output the template
|
|
|
1d2b07 |
# content. This is required because template files might be found
|
|
|
1d2b07 |
# as compressed files inside the repository.
|
|
|
1d2b07 |
local VIEWER="/bin/cat"
|
|
|
1d2b07 |
|
|
|
1d2b07 |
while [[ $COUNTER -lt ${#MODELS[*]} ]];do
|
|
|
1d2b07 |
|
|
|
9b5d35 |
# Verify existence and extension of design models.
|
|
|
9b5d35 |
cli_checkFiles ${MODELS[$COUNTER]} -f --match='\.(svgz|svg)$'
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Define file name for design model instances.
|
|
|
1d2b07 |
MODEL_INSTANCES[$COUNTER]=${TMPDIR}/$(basename ${MODELS[$COUNTER]})
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Define file name for image instances.
|
|
|
1d2b07 |
IMAGE_INSTANCES[$COUNTER]=${TMPDIR}/$(basename ${MODELS[$COUNTER]} \
|
|
|
1d2b07 |
| sed -r 's/\.(svgz|svg)$/.png/')
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Redefine command used to read design models.
|
|
|
1d2b07 |
if [[ $(file -b -i ${MODELS[$COUNTER]}) =~ '^application/x-gzip$' ]];then
|
|
|
1d2b07 |
VIEWER="/bin/zcat"
|
|
|
1d2b07 |
fi
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Create uncompressed design model instances in order to make
|
|
|
1d2b07 |
# color replacements without affecting original design models.
|
|
|
1d2b07 |
$VIEWER ${MODELS[$COUNTER]} > ${MODEL_INSTANCES[$COUNTER]}
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Make your best to be sure the design model instance you are
|
|
|
1d2b07 |
# processing is a valid scalable vector graphic.
|
|
|
1d2b07 |
cli_checkFiles ${MODEL_INSTANCES[$COUNTER]} --mime="text/xml"
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Make color replacements to each design model instance before
|
|
|
1d2b07 |
# render them using Inkscape.
|
|
|
1d2b07 |
if [[ ${FGCOLOR} != '000000' ]];then
|
|
|
1d2b07 |
sed -i -r "s/((fill|stroke):#)000000/\1${FGCOLOR}/g" ${MODEL_INSTANCES[$COUNTER]}
|
|
|
1d2b07 |
fi
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Create list of Inkscape commands based for each design model
|
|
|
1d2b07 |
# set in the configuration file.
|
|
|
9b5d35 |
IMAGE_COMMANDS[${COUNTER}]="${MODEL_INSTANCES[$COUNTER]} \
|
|
|
9b5d35 |
--export-id=${EXPORTID} \
|
|
|
1d2b07 |
--export-png=${IMAGE_INSTANCES[$COUNTER]} \
|
|
|
1d2b07 |
--export-background=$(echo ${BGCOLOR} | cut -d'-' -f1) \
|
|
|
1d2b07 |
--export-background-opacity=$(echo ${BGCOLOR} | cut -d'-' -f2) \
|
|
|
1d2b07 |
--export-height=${HEIGHT}"
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Create PNG image based on design models.
|
|
|
9b5d35 |
inkscape ${IMAGE_COMMANDS[$COUNTER]} > /dev/null
|
|
|
1d2b07 |
|
|
|
1d2b07 |
COUNTER=$(( $COUNTER + 1 ))
|
|
|
1d2b07 |
|
|
|
1d2b07 |
done
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Verify existence of output directory.
|
|
|
1d2b07 |
if [[ ! -d $(dirname ${OUTPUT}) ]];then
|
|
|
1d2b07 |
mkdir -p $(dirname ${OUTPUT})
|
|
|
1d2b07 |
fi
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Apply command to PNG images produced from design models to
|
|
|
1d2b07 |
# construct the final PNG image.
|
|
|
1d2b07 |
cli_printMessage "${OUTPUT}" --as-creating-line
|
|
|
1d2b07 |
${COMMAND} ${IMAGE_INSTANCES[*]} ${OUTPUT}
|
|
|
1d2b07 |
|
|
|
1d2b07 |
# Convert images from PNG to those formats specified in the
|
|
|
1d2b07 |
# configuration file.
|
|
|
1d2b07 |
local TARGET=$(echo $OUTPUT | sed -r 's/\.(.+)$//')
|
|
|
1d2b07 |
for FORMAT in ${FORMATS};do
|
|
|
1d2b07 |
cli_printMessage "${TARGET}.${FORMAT}" --as-creating-line
|
|
|
1d2b07 |
convert ${OUTPUT} ${TARGET}.${FORMAT}
|
|
|
1d2b07 |
done
|
|
|
1d2b07 |
|
|
|
1d2b07 |
}
|