aboutsummaryrefslogtreecommitdiff
path: root/tools/_colorFixer.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/_colorFixer.sh')
-rwxr-xr-xtools/_colorFixer.sh32
1 files changed, 15 insertions, 17 deletions
diff --git a/tools/_colorFixer.sh b/tools/_colorFixer.sh
index 932b7ca90..037499ff1 100755
--- a/tools/_colorFixer.sh
+++ b/tools/_colorFixer.sh
@@ -1,11 +1,12 @@
#!/bin/bash
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-PALETTE_FILE="${DIR}/paletteColors"
+DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+PALETTE_FILE=${DIR}/paletteColors
+FILE_NAME=$1
function hexToRgb {
color=$1
- if [ $(echo $color | wc -c) = 5 ]
+ if [[ $(echo $color | wc -c) = 5 ]]
then
color="#${color:1:1}${color:1:1}${color:2:1}${color:2:1}${color:3:1}${color:3:1}"
fi
@@ -16,14 +17,19 @@ function hexToRgb {
}
function findNearestColor {
+ paletteColors=$(for color in $(cat "$PALETTE_FILE")
+ do
+ echo $(hexToRgb $color)
+ done)
+
rgb1=($(grep -o -P '(\d+(.\d+)?)(?=%)' <<< $1))
r1=${rgb1[0]}
g1=${rgb1[1]}
b1=${rgb1[2]}
-
+
smallestDistance=173
bestColor=''
-
+
while read -r paletteColor
do
rgb2=($(grep -o -P '(\d+(.\d+)?)(?=%)' <<< $paletteColor))
@@ -37,18 +43,10 @@ function findNearestColor {
bestColor=$paletteColor
fi
done <<< $paletteColors
-
echo $bestColor
}
-
-
-paletteColors=$(for color in $(cat "$PALETTE_FILE")
- do
- echo $(hexToRgb $color)
- done)
-
-for file in $(find -name "$1" -maxdepth 1 -type f -printf "%f\n")
+for file in $(find -name "$FILE_NAME" -maxdepth 1 -type f -printf "%f\n")
do
echo ===================================================
echo $file
@@ -56,11 +54,11 @@ do
file_colors=$(grep -o -P -i 'rgb\((\d+(.\d+)?%,?){3}\)|#((\d|[abcdef]){3}){1,2}' $file | sort -u)
for file_color in $file_colors
do
- if [ ${file_color:0:1} = '#' ]
+ if [[ ${file_color:0:1} = '#' ]]
then
- file_color_rgb=$(hexToRgb $file_color)
+ file_color=$(hexToRgb $file_color)
fi
- new_color=$(findNearestColor $file_color_rgb)
+ new_color=$(findNearestColor $file_color)
echo $file_color '->' $new_color
svg=$(sed "s/$file_color/$new_color/g" <<< $svg)