Blame Scripts/Bash/Functions/Render/Svg/svg_convertPngToBranded.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# svg_convertPngToBranded.sh -- This function standardizes image
878a2b
# branding. Once the base PNG image is rendered and the
878a2b
# `--with-brands' option is provided, this function composites a new
c2465f
# branded image using the preferences set in the related
c2465f
# `branding.conf' file.  The `branding.conf' file must be stored
c2465f
# inside the related design model component used as reference to
c2465f
# produce the base PNG image.
878a2b
#
878a2b
# Copyright (C) 2009, 2010, 2011 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function svg_convertPngToBranded {
878a2b
878a2b
    # Verify whether the option `--with-brands' was provided or not to
878a2b
    # `centos-art.sh' script command-line.
878a2b
    if [[ $FLAG_WITH_BRANDS == 'false' ]];then
878a2b
        return
878a2b
    fi
878a2b
878a2b
    local BRANDING_CONF_FILE=''
878a2b
    local BRANDING_CONF_SECTION=''
878a2b
    local BRANDING_CONF_VALUES=''
878a2b
    local BRANDING_CONF_VALUE=''
120005
    local BRANDFILE=''
878a2b
    local POSITION=''
878a2b
    local POSITIONS=''
878a2b
878a2b
    # Define absolute path to branding configuration file.
c2465f
    BRANDING_CONF_FILE="$(dirname ${TEMPLATE})/branding.conf"
878a2b
e57f2e
    # Verify absolute path to branding configuration file. This is
e57f2e
    # required in order to avoid trying to rendered branded content
e57f2e
    # which doesn't have an associated `branding.conf' file.
e57f2e
    cli_checkFiles "$BRANDING_CONF_FILE"
e57f2e
878a2b
    # Define regular expression matching the variable name (i.e., the
878a2b
    # left column), inside the configuration line, you want to match
878a2b
    # on.
c2465f
    BRANDING_CONF_VARNAME=$(basename ${TEMPLATE})
878a2b
878a2b
    # Define list of configuration lines related to current design
878a2b
    # model. This are the lines that tell us how and where to apply
878a2b
    # branding information on base PNG image. Be sure that only
878a2b
    # configuration lines from supported section names (e.g.,
878a2b
    # `symbol', `type', `logo') be read, no need to waste resources
878a2b
    # with others.
e57f2e
878a2b
    BRANDING_CONF_VALUES=$(\
878a2b
        for BRANDING_CONF_SECTION in $(echo "types symbols logos");do
878a2b
            cli_getConfigValue "${BRANDING_CONF_FILE}" "${BRANDING_CONF_SECTION}" "${BRANDING_CONF_VARNAME}"
878a2b
        done)
878a2b
878a2b
    for BRANDING_CONF_VALUE in $BRANDING_CONF_VALUES;do
878a2b
878a2b
        # Define absolute path to image file used as brand. This is
878a2b
        # the image put over the PNG image produced as result of
878a2b
        # design models base rendition.
120005
        BRANDFILE=$(cli_getRepoTLDir)/Identity/Images/Brands/$(echo $BRANDING_CONF_VALUE \
b1430c
            | gawk 'BEGIN{ FS=":" } { print $1 }' \
120005
            | sed -r "s/=BRAND=/${BRAND}/g")
878a2b
878a2b
        # Verify absolute path to image file used as brand. Assuming
878a2b
        # no brand image file is found, continue with the next
878a2b
        # configuration line.
120005
        if [[ ! -f $BRANDFILE ]];then
878a2b
            continue
878a2b
        fi
878a2b
878a2b
        # Define list of positions using the format of ImageMagick
878a2b
        # `-geometry' option argument. 
878a2b
        POSITIONS=$(echo "$BRANDING_CONF_VALUE" | cut -d: -f2- | tr ':' ' ')
878a2b
878a2b
        # Loop through list of brand image positions and use the
c2465f
        # composite command from ImageMagick, to overlap the unbranded
c2465f
        # image just rendered with the branded version of itself.
878a2b
        for POSITION in $POSITIONS;do
120005
            composite -geometry ${POSITION} ${BRANDFILE} ${FILE}.png ${FILE}.png
878a2b
        done
878a2b
878a2b
    done
878a2b
878a2b
}