From b5474dba71da6f66fcb89f8e91626c7577301575 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Fri, 8 Jan 2021 23:39:53 -0500 Subject: [PATCH] Clean up "svg2img" * Use arrays to store repeated image sizes * Add verbose flag to rm * Add echoes throughout the program * Move whitespace in template/sed statements --- svg2img | 47 ++++++++++++++++++++++++++------------------- template/circle.svg | 2 +- template/square.svg | 2 +- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/svg2img b/svg2img index e632960..56915d0 100755 --- a/svg2img +++ b/svg2img @@ -2,47 +2,51 @@ # Converts my logo to various formats from a template SVG # Armaan Bhojwani 2021 +SIZES=(2048 1024 512 256 128 64) +A_SIZES=(10 15 20 25 30 35 40 45 50 55 60) + [[ -z ${1} ]] && echo "Please provide an output format!" && exit 1 -[[ ${1} == "svg" ]] && find . -name *.svg -not -path "./template/*" -exec rm {} \; +[[ ${1} == "svg" ]] && find . -name *.svg -not -path "./template/*" -exec rm -v {} \; if [[ (! -d "square/svg" || ! -d "circle/svg") || (${1} == "svg") ]]; then + echo "Generating SVGs" for SHAPE in square circle; do mkdir -pv ${SHAPE}/svg - sed -e 's/STROKE/stroke="#00ffbf" /g' \ + sed -e 's/STROKE/stroke="#00ffbf"/g' \ -e 's/FILL/#212121/g' template/${SHAPE}.svg \ > ${SHAPE}/svg/logo-${SHAPE}-color-dark.svg - sed -e 's/STROKE/stroke="#00ffbf" /g' \ + sed -e 's/STROKE/stroke="#00ffbf"/g' \ -e 's/FILL/#fff/g' template/${SHAPE}.svg \ > ${SHAPE}/svg/logo-${SHAPE}-color-white.svg - sed -e 's/STROKE/stroke="#00ffbf" /g' \ + sed -e 's/STROKE/stroke="#00ffbf"/g' \ -e 's/FILL/none/g' template/${SHAPE}.svg \ > ${SHAPE}/svg/logo-${SHAPE}-color-trans.svg - sed -e 's/STROKE/stroke="#212121" /g' \ + sed -e 's/STROKE/stroke="#212121"/g' \ -e 's/FILL/#00ffbf/g' template/${SHAPE}.svg \ > ${SHAPE}/svg/logo-${SHAPE}-dark-color.svg - sed -e 's/STROKE/stroke="#212121" /g' \ + sed -e 's/STROKE/stroke="#212121"/g' \ -e 's/FILL/#fff/g' template/${SHAPE}.svg \ > ${SHAPE}/svg/logo-${SHAPE}-dark-white.svg - sed -e 's/STROKE/stroke="#212121" /g' \ + sed -e 's/STROKE/stroke="#212121"/g' \ -e 's/FILL/none/g' template/${SHAPE}.svg \ > ${SHAPE}/svg/logo-${SHAPE}-dark-trans.svg - sed -e 's/STROKE/stroke="#fff" /g' \ + sed -e 's/STROKE/stroke="#fff"/g' \ -e 's/FILL/#00ffbf/g' template/${SHAPE}.svg \ > ${SHAPE}/svg/logo-${SHAPE}-white-color.svg - sed -e 's/STROKE/stroke="#fff" /g' \ + sed -e 's/STROKE/stroke="#fff"/g' \ -e 's/FILL/#212121/g' template/${SHAPE}.svg \ > ${SHAPE}/svg/logo-${SHAPE}-white-dark.svg - sed -e 's/STROKE/stroke="#fff" /g' \ + sed -e 's/STROKE/stroke="#fff"/g' \ -e 's/FILL/none/g' template/${SHAPE}.svg \ > ${SHAPE}/svg/logo-${SHAPE}-white-trans.svg done @@ -50,15 +54,16 @@ fi [[ ${1} == "svg" ]] && exit 0 -[[ ${1} == "png" ]] && find . -name *.png -exec rm {} \; +[[ ${1} == "png" ]] && find . -name *.png -exec rm -v {} \; if [[ (! -d "square/png" || ! -d "circle/png") || (${1} == "png") ]]; then + echo "Generating PNGs" for SHAPE in square circle; do - for i in 2048 1024 512 256 128; do + for i in ${SIZES[@]}; do mkdir -pv ${SHAPE}/png/${i} done - for i in 2048 1024 512 256 128; do + for i in ${SIZES[@]}; do for SVGIN in square/svg/*; do BASE=$(basename ${SVGIN} | cut -d '.' -f 1) inkscape -w ${i} -h ${i} ${SVGIN} --export-filename \ @@ -77,9 +82,10 @@ fi [[ ${1} == "png" ]] && exit 0 if [[ ${1} == "ascii" ]]; then - find . -name *ascii.txt -exec rm {} \; + echo "Generating ASCII art" + find . -name *ascii.txt -exec rm -v {} \; for SHAPE in square circle; do - for i in 10 15 20 25 30 35 40 45 50; do + for i in ${A_SIZES[@]}; do mkdir -pv ${SHAPE}/ascii/${i} for PNGIN in circle/png/2048/*; do @@ -97,9 +103,10 @@ if [[ ${1} == "ascii" ]]; then fi if [[ ${1} == "unicode" ]]; then - find . -name *unicode.txt -exec rm {} \; + echo "Generating Unicode" + find . -name *unicode.txt -exec rm -v {} \; for SHAPE in square circle; do - for i in 10 15 20 25 30 35 40 45 50; do + for i in ${A_SIZES[@]}; do mkdir -pv ${SHAPE}/unicode/${i} for PNGIN in circle/png/2048/*; do @@ -119,14 +126,14 @@ if [[ ${1} == "unicode" ]]; then fi for SHAPE in square circle; do - find . -name *.${1} -exec rm {} \; + find . -name *.${1} -exec rm -v {} \; - for i in 2048 1024 512 256 128; do + for i in ${SIZES[@]}; do mkdir -pv ${SHAPE}/${1}/${i} done - # for PAT in $(find -name *.png); do while read PAT; do + echo "Generating ${1}s" convert -verbose ${PAT} ${PAT//png/${1}} done < <(find -name *.png) done diff --git a/template/circle.svg b/template/circle.svg index 5210884..143a94e 100644 --- a/template/circle.svg +++ b/template/circle.svg @@ -1,5 +1,5 @@ - + diff --git a/template/square.svg b/template/square.svg index 8241d93..690acea 100644 --- a/template/square.svg +++ b/template/square.svg @@ -1,5 +1,5 @@ - + -- 2.39.2