diff options
author | 2018-03-15 15:23:35 +0100 | |
---|---|---|
committer | 2018-03-15 15:23:35 +0100 | |
commit | 26bd2d765a05fc9ca94d7c7b22df82135ca50d0b (patch) | |
tree | dbe843eaa30f218e13fa535d058e883531a0082e /tools | |
parent | 4cfd122a7096758cd51a58276d31c804237ef143 (diff) | |
download | flat-remix-26bd2d765a05fc9ca94d7c7b22df82135ca50d0b.tar.gz flat-remix-26bd2d765a05fc9ca94d7c7b22df82135ca50d0b.zip |
Add colorFixer.sh
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/colorFixer.sh | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tools/colorFixer.sh b/tools/colorFixer.sh new file mode 100755 index 000000000..96d15233a --- /dev/null +++ b/tools/colorFixer.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +paletteColors=( + 'rgb(0%,0%,0%)' + 'rgb(100%,100%,100%)' + 'rgb(97.647059%,87.058824%,41.176471%)' + 'rgb(100%,78.431373%,19.215686%)' + 'rgb(100%,78.431373%,19.215686%)' + 'rgb(5.882353%,63.137255%,37.254902%)' + 'rgb(10.588235%,63.921569%,53.72549%)' + 'rgb(90.196078%,90.196078%,90.196078%)' + 'rgb(27.058824%,27.058824%,27.058824%)' + 'rgb(32.156863%,70.196078%,85.098039%)' + 'rgb(21.176471%,48.235294%,94.117647%)' + 'rgb(72.941176%,9.019608%,30.588235%)' +) + +function findNearestColor { + rgb1=($(grep -o -P '(\d+(.\d+)?)(?=%)' <<< $1)) + r1=${rgb1[0]} + g1=${rgb1[1]} + b1=${rgb1[2]} + + smallerDistance=173 + bestColor='' + + for paletteColor in ${paletteColors[@]} + do + rgb2=($(grep -o -P '(\d+(.\d+)?)(?=%)' <<< $paletteColor)) + r2=${rgb2[0]} + g2=${rgb2[1]} + b2=${rgb2[2]} + distance=$(echo "scale=3;sqrt(($r2-$r1)^2 + ($g2-$g1)^2 + ($b2-$b1)^2)" | bc) + if (( $(echo $distance'<'$smallerDistance | bc) )) + then + smallerDistance=$distance + bestColor=$paletteColor + fi + done + + echo $bestColor +} + + +for file in $(find -maxdepth 1 -type f -printf "%f\n") +do + echo =================================================== + svg=$(cat $file) + file_colors=$(grep -o -P 'rgb\((\d+(.\d+)?%,?){3}\)' $file) + for file_color in $file_colors + do + new_color=$(findNearestColor $file_color) + echo $file_color '->' $new_color + + svg=$(sed "s/$file_color/$new_color/g" <<< $svg) + done + echo $svg > $file +done |