Blame Automation/centos-art.sh-render/Conf/conf_setBaseRendition.sh

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