to_ansi.sh (1421B)
1 #!/bin/bash 2 3 set -e 4 5 file="$1" 6 width="$2" 7 8 colors=(78,78,78 255,108,96 0,170,0 288,288,182 150,203,254 255,115,253 85,255,255 238,238,238 124,124,124 255,155,147 177,253,121 255,255,145 181,220,254 255,156,254 85,255,255 255,255,255) 9 args=() 10 for i in `seq 0 15`; do 11 if test $i -ge 8; then 12 color=$((i+8)) 13 else 14 color=$((i)) 15 fi 16 args+=(-fuzz 0% -fill "gray(${color})" -opaque "rgb(${colors[$i]})") 17 done 18 19 convert "$file" -resize "${width}x" png:- \ 20 | convert +dither -remap "$(dirname "$0")/travis-palette.gif" png:- gif:- \ 21 | convert gif:- "${args[@]}" gif:- \ 22 | convert gif:- pgm:- \ 23 | tail -n +4 \ 24 | hexdump -Cv \ 25 | sed -n -e 's/^[0-9a-f]* \(\([0-9a-f]\{2\} \?\)\{1,16\}\).*$/\1/p' \ 26 | tr '\n' ' ' \ 27 | sed -e 's/ \+/ /g' \ 28 | fold -w $((width*3)) \ 29 | while read a && read b; do for i in $a; do echo -n "$i ${b%% *} "; b="${b#* }"; done; echo; done \ 30 | fold -w $((width*6)) \ 31 | sed -e 's/\([01]\)\([0-7]\) \([01]\)\([0-7]\) /[\1;3\2;4\4mâ–€/g' -e 's/$/[m/' \ 32 | if test "$CI" = "true" -a "$TRAVIS" = "true"; then sed -e 's/â–€/"/g'; else cat; fi 33 # Using the line below instead of the one above will ensure that the output is 34 # printed slow enought that unicode corruption by Travis is unlikely. 35 # 36 # | if test "$CI" = "true" -a "$TRAVIS" = "true"; then while IFS=$'\n' read -n 11 ab; do if test "${#ab}" -ne 11; then echo "$ab"; else echo -n "$ab"; fi; sleep 0.01; done; else cat; fi 37 echo 38