]> git.armaanb.net Git - logo.git/commitdiff
Clean up "svg2img"
authorArmaan Bhojwani <me@armaanb.net>
Sat, 9 Jan 2021 04:39:53 +0000 (23:39 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Sat, 9 Jan 2021 04:39:53 +0000 (23:39 -0500)
* Use arrays to store repeated image sizes
* Add verbose flag to rm
* Add echoes throughout the program
* Move whitespace in template/sed statements

svg2img
template/circle.svg
template/square.svg

diff --git a/svg2img b/svg2img
index e632960edf2d8a7facbe7f810f334bcb6afdced0..56915d0b252b9f5fefbc9f73af03d7127ef2f6f7 100755 (executable)
--- 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
index 5210884e324653a61cec44a6119664708b45d029..143a94e384b8f851d8d4813fca62ff3f9fca0bc5 100644 (file)
@@ -1,5 +1,5 @@
 <svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
- <g STROKEstroke-width="6">
+ <g STROKE stroke-width="6">
    <circle cx="50" cy="50" r="47" fill="FILL"/>
    <line x1="17" y1="17" x2="50" y2="50"/>
    <line x1="17" y1="83" x2="83" y2="17"/>
index 8241d93dffbb6c0f7648865fb60c1a9eee43fb7b..690aceadab409041eeacee4a955655a7cf569efd 100644 (file)
@@ -1,5 +1,5 @@
 <svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
- <g STROKEstroke-width="6">
+ <g STROKE stroke-width="6">
    <rect x="3" y="3" width="94" height="94" fill="FILL"/>
    <line x1="3" y1="3" x2="50" y2="50"/>
    <line x1="97" y1="3" x2="3" y2="97"/>