]> git.armaanb.net Git - logo.git/blob - svg2img
Ignore the pregenerated logo when running svg2img
[logo.git] / svg2img
1 #!/usr/bin/env bash
2 # Converts my logo to various formats from a template SVG
3 # Armaan Bhojwani 2021
4
5 SIZES=(2048 1024 512 256 128 64)
6 A_SIZES=(10 15 20 25 30 35 40 45 50 55 60)
7
8 for arg in ${@};do
9   [[ -z ${arg} ]] && echo "Please provide an output format!" && exit 1
10   
11   [[ ${arg} == "svg" ]] && find . -name *.svg -not -path "./template/*" \
12     -exec rm -v {} \;
13   
14   if [[ (! -d "square/svg" || ! -d "circle/svg") || (${arg} == "svg") ]]; then
15     echo "Generating SVGs"
16     for SHAPE in square circle; do
17       mkdir -pv ${SHAPE}/svg
18   
19       sed -e 's/STROKE/stroke="#00ffbf"/g' \
20         -e 's/FILL/#212121/g' template/${SHAPE}.svg \
21         > ${SHAPE}/svg/logo-${SHAPE}-color-dark.svg
22   
23       sed -e 's/STROKE/stroke="#00ffbf"/g' \
24         -e 's/FILL/#fff/g' template/${SHAPE}.svg \
25         > ${SHAPE}/svg/logo-${SHAPE}-color-white.svg
26   
27       sed -e 's/STROKE/stroke="#00ffbf"/g' \
28         -e 's/FILL/none/g' template/${SHAPE}.svg \
29         > ${SHAPE}/svg/logo-${SHAPE}-color-trans.svg
30   
31       sed -e 's/STROKE/stroke="#212121"/g' \
32         -e 's/FILL/#00ffbf/g' template/${SHAPE}.svg \
33         > ${SHAPE}/svg/logo-${SHAPE}-dark-color.svg
34   
35       sed -e 's/STROKE/stroke="#212121"/g' \
36         -e 's/FILL/#fff/g' template/${SHAPE}.svg \
37         > ${SHAPE}/svg/logo-${SHAPE}-dark-white.svg
38   
39       sed -e 's/STROKE/stroke="#212121"/g' \
40         -e 's/FILL/none/g' template/${SHAPE}.svg \
41         > ${SHAPE}/svg/logo-${SHAPE}-dark-trans.svg
42   
43       sed -e 's/STROKE/stroke="#fff"/g' \
44         -e 's/FILL/#00ffbf/g' template/${SHAPE}.svg \
45         > ${SHAPE}/svg/logo-${SHAPE}-white-color.svg
46   
47       sed -e 's/STROKE/stroke="#fff"/g' \
48         -e 's/FILL/#212121/g' template/${SHAPE}.svg \
49         > ${SHAPE}/svg/logo-${SHAPE}-white-dark.svg
50   
51       sed -e 's/STROKE/stroke="#fff"/g' \
52         -e 's/FILL/none/g' template/${SHAPE}.svg \
53         > ${SHAPE}/svg/logo-${SHAPE}-white-trans.svg
54     done
55   fi
56   
57   [[ ${arg} == "svg" ]] && exit 0
58   
59   [[ ${arg} == "png" ]] && find . -name *.png -not -iwholename ./logo.png \
60     -exec rm -v {} \;
61   
62   if [[ (! -d "square/png" || ! -d "circle/png") || (${arg} == "png") ]]; then
63     echo "Generating PNGs"
64     for SHAPE in square circle; do
65       for i in ${SIZES[@]}; do
66         mkdir -pv ${SHAPE}/png/${i}
67       done
68   
69       for i in ${SIZES[@]}; do
70         for SVGIN in square/svg/*; do
71           BASE=$(basename ${SVGIN} | cut -d '.' -f 1)
72           inkscape -w ${i} -h ${i} ${SVGIN} --export-filename \
73             square/png/${i}/${BASE}-${i}.png
74         done
75   
76         for SVGIN in circle/svg/*; do
77           BASE=$(basename ${SVGIN} | cut -d '.' -f 1)
78           inkscape -w ${i} -h ${i} ${SVGIN} --export-filename \
79             circle/png/${i}/${BASE}-${i}.png
80         done
81       done
82     done
83   fi
84   
85   [[ ${arg} == "png" ]] && exit 0
86   
87   if [[ ${arg} == "ascii" ]]; then
88     echo "Generating ASCII art"
89     find . -name *ascii.txt -exec rm -v {} \;
90     for SHAPE in square circle; do
91       for i in ${A_SIZES[@]}; do
92         mkdir -pv ${SHAPE}/ascii/${i}
93   
94         for PNGIN in circle/png/2048/*; do
95           BASE=$(basename ${PNGIN} | cut -d '.' -f 1)
96           jp2a --height=${i} ${PNGIN} > circle/ascii/${i}/${BASE}-${i}.ascii.txt
97         done
98   
99         for PNGIN in square/png/2048/*; do
100           BASE=$(basename ${PNGIN} | cut -d '.' -f 1)
101           jp2a --height=${i} ${PNGIN} > square/ascii/${i}/${BASE}-${i}.ascii.txt
102         done
103       done
104     done
105     exit 0
106   fi
107   
108   if [[ ${arg} == "unicode" ]]; then
109     echo "Generating Unicode"
110     find . -name *unicode.txt -exec rm -v {} \;
111     for SHAPE in square circle; do
112       for i in ${A_SIZES[@]}; do
113         mkdir -pv ${SHAPE}/unicode/${i}
114   
115         for PNGIN in circle/png/2048/*; do
116           BASE=$(basename ${PNGIN} | cut -d '-' -f -4)
117           chafa -c none -s ${i}x${i} ${PNGIN} \
118             > circle/unicode/${i}/${BASE}-${i}.unicode.txt
119         done
120   
121         for PNGIN in square/png/2048/*; do
122           BASE=$(basename ${PNGIN} | cut -d '-' -f -4)
123           chafa -c none -s ${i}x${i} ${PNGIN} \
124             > square/unicode/${i}/${BASE}-${i}.unicode.txt
125         done
126       done
127     done
128     exit 0
129   fi
130   
131   for SHAPE in square circle; do
132     find . -name *.${arg} -exec rm -v {} \;
133   
134     for i in ${SIZES[@]}; do
135       mkdir -pv ${SHAPE}/${arg}/${i}
136     done
137   
138     while read PAT; do
139       echo "Generating ${arg}s"
140       convert -verbose ${PAT} ${PAT//png/${arg}}
141     done < <(find -name *.png -not -iwholename ./logo.png)
142   done
143 done