Skip to content

Instantly share code, notes, and snippets.

@ktilcu
Last active August 15, 2017 20:49
Show Gist options
  • Select an option

  • Save ktilcu/13692a42059ef569b0b3 to your computer and use it in GitHub Desktop.

Select an option

Save ktilcu/13692a42059ef569b0b3 to your computer and use it in GitHub Desktop.
kyle-Snippet: Colorize PNG of text and quantize
#!/bin/bash
set -o pipefail -o errexit -o noglob -o nounset
function usage() {
cat <<EOUSAGE
Usage: textImageProcessor [OPTIONS] ...
Colorizes and/or optimizes rasterized text.
OPTION DESCRIPTION
========== ==================================================================
-c Hex color for colorizing (must include '#')
-h This text
EOUSAGE
}
function printErr() {
echo -e "$1" >&2
}
function includeHash() {
printErr "Make sure to include a hash at the beginning of your Hex color;"
printErr "e.g., '#000'"
exit 1
}
c=''
while getopts ":c:h" o; do
case "${o}" in
c)
c=${OPTARG}
[[ $c =~ ^\# ]] || includeHash
;;
h)
usage
exit 0
;;
*)
usage >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
if [ $# -ne 0 ]; then
printErr "No args are accepted \n"
usage >&2
exit 1
fi
if [ -z "${c}" ]; then
pngquant --speed 1 --nofs 6 -
else
convert - \( -clone 0 -fill "$c" -draw 'color 0,0 reset' \) -compose Atop -composite - |
pngquant --speed 1 --nofs 6 -
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment