-#!/usr/bin/env bash
+#!/bin/sh
# Converts my logo to various formats from a template SVG
# Armaan Bhojwani 2021
-[[ -z ${1} ]] && echo "Please provide an output format!" && exit 1
-
-[[ ${1} == "svg" ]] && find . -name *.svg -not -path "./template/*" -exec rm {} \;
-
-if [[ (! -d "square/svg" || ! -d "circle/svg") || (${1} == "svg") ]]; then
- for SHAPE in square circle; do
- mkdir -pv ${SHAPE}/svg
-
- sed -e 's/STROKE/stroke="#00ffbf" /g' \
- -e 's/FILL/ fill="#212121"/g' template/${SHAPE}.svg \
- > ${SHAPE}/svg/logo-${SHAPE}-color-dark.svg
-
- sed -e 's/STROKE/stroke="#00ffbf" /g' \
- -e 's/FILL/ fill="#fff"/g' template/${SHAPE}.svg \
- > ${SHAPE}/svg/logo-${SHAPE}-color-white.svg
-
- sed -e 's/STROKE/stroke="#00ffbf" /g' \
- -e 's/FILL//g' template/${SHAPE}.svg \
- > ${SHAPE}/svg/logo-${SHAPE}-color-trans.svg
-
- sed -e 's/STROKE/stroke="#212121" /g' \
- -e 's/FILL/ fill="#00ffbf"/g' template/${SHAPE}.svg \
- > ${SHAPE}/svg/logo-${SHAPE}-dark-color.svg
-
- sed -e 's/STROKE/stroke="#212121" /g' \
- -e 's/FILL/ fill="#fff"/g' template/${SHAPE}.svg \
- > ${SHAPE}/svg/logo-${SHAPE}-dark-white.svg
-
- sed -e 's/STROKE/stroke="#212121" /g' \
- -e 's/FILL//g' template/${SHAPE}.svg \
- > ${SHAPE}/svg/logo-${SHAPE}-dark-trans.svg
-
- sed -e 's/STROKE/stroke="#fff" /g' \
- -e 's/FILL/ fill="#00ffbf"/g' template/${SHAPE}.svg \
- > ${SHAPE}/svg/logo-${SHAPE}-white-color.svg
-
- sed -e 's/STROKE/stroke="#fff" /g' \
- -e 's/FILL/ fill="#212121"/g' template/${SHAPE}.svg \
- > ${SHAPE}/svg/logo-${SHAPE}-white-dark.svg
-
- sed -e 's/STROKE/stroke="#fff" /g' \
- -e 's/FILL//g' template/${SHAPE}.svg \
- > ${SHAPE}/svg/logo-${SHAPE}-white-trans.svg
- done
-fi
-
-[[ ${1} == "svg" ]] && exit 0
-
-[[ ${1} == "png" ]] && find . -name *.png -exec rm {} \;
-
-if [[ (! -d "square/png" || ! -d "circle/png") || (${1} == "png") ]]; then
- for SHAPE in square circle; do
- for i in 2048 1024 512 256 128; do
- mkdir -pv ${SHAPE}/png/${i}
+set -e
+
+SIZES="2048 1024 512 256 128 64"
+A_SIZES="10 15 20 25 30 35 40 45 50 55 60"
+
+for arg in ${@};do
+ [ -z ${arg} ] && echo "Please provide an output format!" && exit 1
+
+ [ ${arg} = "svg" ] && find . -name *.svg -not -path "./template/*" \
+ -exec rm -v {} \;
+
+ if [ ! -d "square/svg" ] || [ ! -d "circle/svg" ] || [ ${arg} = "svg" ]; then
+ echo "Generating SVGs"
+ for SHAPE in square circle; do
+ mkdir -p ${SHAPE}/svg
+
+ 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' \
+ -e 's/FILL/#fff/g' template/${SHAPE}.svg \
+ > ${SHAPE}/svg/logo-${SHAPE}-color-white.svg
+
+ 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' \
+ -e 's/FILL/#00ffbf/g' template/${SHAPE}.svg \
+ > ${SHAPE}/svg/logo-${SHAPE}-dark-color.svg
+
+ 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' \
+ -e 's/FILL/none/g' template/${SHAPE}.svg \
+ > ${SHAPE}/svg/logo-${SHAPE}-dark-trans.svg
+
+ 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' \
+ -e 's/FILL/#212121/g' template/${SHAPE}.svg \
+ > ${SHAPE}/svg/logo-${SHAPE}-white-dark.svg
+
+ sed -e 's/STROKE/stroke="#fff"/g' \
+ -e 's/FILL/none/g' template/${SHAPE}.svg \
+ > ${SHAPE}/svg/logo-${SHAPE}-white-trans.svg
done
-
- for i in 2048 1024 512 256 128; do
- for SVGIN in square/svg/*; do
- BASE=$(basename ${SVGIN} | cut -d '.' -f 1)
- inkscape -w ${i} -h ${i} ${SVGIN} --export-filename \
- square/png/${i}/${BASE}-${i}.png
+ fi
+
+ [ ${arg} = "svg" ] && exit 0
+
+ [ ${arg} = "png" ] && find . -name *.png -not -name ./logo.png \
+ -exec rm -v {} \;
+
+ if [ ! -d "square/png" ] || [ ! -d "circle/png" ] || [ ${arg} = "png" ]; then
+ echo "Generating PNGs"
+ for SHAPE in square circle; do
+ set -- $SIZES
+ for i in $@; do
+ mkdir -p ${SHAPE}/png/${i}
done
-
- for SVGIN in circle/svg/*; do
- BASE=$(basename ${SVGIN} | cut -d '.' -f 1)
- inkscape -w ${i} -h ${i} ${SVGIN} --export-filename \
- circle/png/${i}/${BASE}-${i}.png
+
+ for i in $@; do
+ for SVGIN in square/svg/*; do
+ BASE=$(basename ${SVGIN} | cut -d '.' -f 1)
+ inkscape -w ${i} -h ${i} ${SVGIN} --export-filename \
+ square/png/${i}/${BASE}-${i}.png
+ done
+
+ for SVGIN in circle/svg/*; do
+ BASE=$(basename ${SVGIN} | cut -d '.' -f 1)
+ inkscape -w ${i} -h ${i} ${SVGIN} --export-filename \
+ circle/png/${i}/${BASE}-${i}.png
+ done
done
done
- done
-fi
-
-[[ ${1} == "png" ]] && exit 0
-
-if [[ ${1} == "ascii" ]]; then
- find . -name *ascii.txt -exec rm {} \;
- for SHAPE in square circle; do
- for i in 10 15 20 25 30 35 40 45 50; do
- mkdir -pv ${SHAPE}/ascii/${i}
-
- for PNGIN in circle/png/2048/*; do
- BASE=$(basename ${PNGIN} | cut -d '.' -f 1)
- jp2a --height=${i} ${PNGIN} > circle/ascii/${i}/${BASE}-${i}.ascii.txt
+ fi
+
+ [ ${arg} = "png" ] && exit 0
+
+ if [ ${arg} = "ascii" ]; then
+ echo "Generating ASCII art"
+ find . -name *ascii.txt -exec rm -v {} \;
+ for SHAPE in square circle; do
+ set -- $A_SIZES
+ for i in $@; do
+ mkdir -p ${SHAPE}/ascii/${i}
+
+ for PNGIN in circle/png/2048/*; do
+ BASE=$(basename ${PNGIN} | cut -d '.' -f 1)
+ jp2a --height=${i} ${PNGIN} > circle/ascii/${i}/${BASE}-${i}.ascii.txt
+ done
+
+ for PNGIN in square/png/2048/*; do
+ BASE=$(basename ${PNGIN} | cut -d '.' -f 1)
+ jp2a --height=${i} ${PNGIN} > square/ascii/${i}/${BASE}-${i}.ascii.txt
+ done
done
-
- for PNGIN in square/png/2048/*; do
- BASE=$(basename ${PNGIN} | cut -d '.' -f 1)
- jp2a --height=${i} ${PNGIN} > square/ascii/${i}/${BASE}-${i}.ascii.txt
+ done
+ exit 0
+ fi
+
+ if [ ${arg} = "unicode" ]; then
+ echo "Generating Unicode"
+ find . -name *unicode.txt -exec rm -v {} \;
+ for SHAPE in square circle; do
+ set -- $A_SIZES
+ for i in $@; do
+ mkdir -p ${SHAPE}/unicode/${i}
+
+ for PNGIN in circle/png/2048/*; do
+ BASE=$(basename ${PNGIN} | cut -d '-' -f -4)
+ chafa -c none -s ${i}x${i} ${PNGIN} \
+ > circle/unicode/${i}/${BASE}-${i}.unicode.txt
+ done
+
+ for PNGIN in square/png/2048/*; do
+ BASE=$(basename ${PNGIN} | cut -d '-' -f -4)
+ chafa -c none -s ${i}x${i} ${PNGIN} \
+ > square/unicode/${i}/${BASE}-${i}.unicode.txt
+ done
done
done
- done
- exit 0
-fi
-
-if [[ ${1} == "unicode" ]]; then
- find . -name *unicode.txt -exec rm {} \;
+ exit 0
+ fi
+
for SHAPE in square circle; do
- for i in 10 15 20 25 30 35 40 45 50; do
- mkdir -pv ${SHAPE}/unicode/${i}
-
- for PNGIN in circle/png/2048/*; do
- BASE=$(basename ${PNGIN} | cut -d '-' -f -4)
- chafa -c none -s ${i}x${i} ${PNGIN} \
- > circle/unicode/${i}/${BASE}-${i}.unicode.txt
- done
-
- for PNGIN in square/png/2048/*; do
- BASE=$(basename ${PNGIN} | cut -d '-' -f -4)
- chafa -c none -s ${i}x${i} ${PNGIN} \
- > square/unicode/${i}/${BASE}-${i}.unicode.txt
- done
+ find . -name '*.${arg}' -exec rm -v {} \;
+
+ set -- $SIZES
+ for i in $@; do
+ mkdir -p ${SHAPE}/${arg}/${i}
done
- done
- exit 0
-fi
-
-for SHAPE in square circle; do
- find . -name *.${1} -exec rm {} \;
- for i in 2048 1024 512 256 128; do
- mkdir -pv ${SHAPE}/${1}/${i}
+ for PAT in $(find . -name '*.png' -not -name ./logo.png); do
+ echo "Generating ${arg}s"
+ convert -verbose ${PAT} $(printf "%s" "$PAT" | sed "s/\.png/.$arg/g")
+ done
done
-
- # for PAT in $(find -name *.png); do
- while read PAT; do
- convert -verbose ${PAT} ${PAT//png/${1}}
- done < <(find -name *.png)
done