Skip to content

Instantly share code, notes, and snippets.

@MikeiLL
Last active July 27, 2017 19:42
Show Gist options
  • Select an option

  • Save MikeiLL/47c6cb0b6b86ffd7eace0b141c74f178 to your computer and use it in GitHub Desktop.

Select an option

Save MikeiLL/47c6cb0b6b86ffd7eace0b141c74f178 to your computer and use it in GitHub Desktop.
#/usr/bin/bash
# Loop through jpg images and apply sips, mkbitmap and potrace
# http://potrace.sourceforge.net/
if [ $1 == '--help' ]; then
echo "Two optional parameters: filename and threshold. Otherwise vectorizes as .jpg in current dir.";
exit 1;
fi
# If there's already a bitmap directory, we probably already filled
# it with the converted bitmap files
if [ ! -d Bitmaps ]; then
echo "making directory, Bitmaps";
mkdir -p Bitmaps;
sips -s format bmp *.JPG --out Bitmaps
fi
case $1 in
# If the first argument is not a number,
# Treat it as a file name
''|*[!0-9\.]*)
filename=$1;;
*) echo "No filename specified, vectorizing all in current directory." ;;
esac
if [ -n "$filename" ]; then
echo "Vectorizing" $filename;
sips -s format bmp $filename --out .;
# Source: https://stackoverflow.com/a/965072/2223106
basenameonly=$(basename "$filename")
basenameonly="${basenameonly%.*}"
bitmap="${basenameonly##*/}".bmp;
pbmfile="${basenameonly##*/}".pbm;
if [[ $2 ]] ; then
say "with threshold of " $2;
mkbitmap -t $2 $bitmap;
else
mkbitmap $bitmap;
fi
potrace $pbmfile --svg;
say "One Vector generated.";
exit 1;
fi
if [[ $1 ]] ; then
say "Vectorizing with threshold of " $1;
for i in Bitmaps/*.bmp; do mkbitmap -t $1 $i; done;
else
for i in Bitmaps/*.bmp; do mkbitmap; done;
fi
n=0
for i in Bitmaps/*.pbm; do
((n++))
potrace $i --svg;
done
echo "Removing the PBM files";
rm Bitmaps/*.pbm
say $n "Vectors generated."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment