Last active
September 23, 2015 17:26
-
-
Save phx/dea61821d2e55053ffd1 to your computer and use it in GitHub Desktop.
OS X port of img2sf: A script to generate screenfetch ASCII from an image.
Original img2sf project link: https://github.com/cbarox/scripts/tree/master/img2sf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dependencies: img2xterm (not available via Homebrew -- you will need to build from source, see below) | |
Rossy's img2xterm project link: https://github.com/rossy/img2xterm | |
Notes: I had to re-install ImageMagick for img2xterm to work properly. | |
Instructions: | |
$ brew update | |
$ brew reinstall imagemagick | |
$ git clone https://github.com/rossy/img2xterm.git | |
$ cd img2xterm && make && make install | |
Original img2sf raw script: https://raw.githubusercontent.com/cbarox/scripts/master/img2sf/img2sf | |
Below is how I modified the img2sf script to work with OS X (tested on version 10.10.4): | |
Also: | |
Since OS X uses BSD sed, which doesn't support the -i flag, I originally modified the script to use GNU sed, which I installed via Homebrew. However, I have since modified the script to support the BSD version of sed that ships natively with OS X (or Xcode -- not sure). I would still advise using gsed, since the use of the -i flag is cleaner and doesn't require as much additional code and/or cleanup. | |
Changes: | |
Removed Line 16: echo 'startline="0"' > $2 | |
Removed Line 17: echo 'fulloutput=(' >> $2 | |
Modified Line 25: spaces=$(expr "$imgw" - "$nspaces" - "$nup" - "$ndown" 2>/dev/null) | |
Removed Line 28: echo ")" >> $2 | |
Removed Line 30: sed -i "0,/%s/{s/%s/ %s/}" "$2" | |
Added Line 31: sed 's/"//g' "$2" > osx.tmp; mv osx.tmp "$2" | |
Added Line 32: sed 's/%s//g' "$2" > osx.tmp; mv osx.tmp "$2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -eq 0 ]; then | |
echo -e " \n \t ERROR: No arguments provided" | |
echo -e " \t USAGE: img2sf <path/to/image> <path/to/output>\n" | |
exit 1 | |
fi | |
imgw=$(convert -print "%w\n" "$1" /dev/null) | |
# generate the image | |
TMPFILE="tmp" | |
img2xterm "$1" > $TMPFILE | |
# form the output file | |
IFS='' | |
cat $TMPFILE | | |
while read line | |
do | |
nspaces=$(grep -o " " <<< "$line" | wc -l) | |
nup=$(grep -o "ΓûÇ" <<< "$line" | wc -l) | |
ndown=$(grep -o "Γûä" <<< "$line" | wc -l) | |
spaces=$(expr "$imgw" - "$nspaces" - "$nup" - "$ndown" 2>/dev/null) | |
printf "\"%s%${spaces}s %%s\"\n" "$line" "" >> $2 | |
done | |
sed 's/"//g' "$2" > osx.tmp; mv osx.tmp "$2" | |
sed 's/%s//g' "$2" > osx.tmp; mv osx.tmp "$2" | |
# clean up | |
rm $TMPFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment