Skip to content

Instantly share code, notes, and snippets.

@samthor
Last active June 6, 2019 05:00
Show Gist options
  • Save samthor/f19290225a763c2df13bd48f1915dee8 to your computer and use it in GitHub Desktop.
Save samthor/f19290225a763c2df13bd48f1915dee8 to your computer and use it in GitHub Desktop.
Helpers to compress PNG images
#!/bin/bash
command_exists() {
type "$1" &> /dev/null
}
for X in "$@"; do
if [ ${X: -4} == '.png' ]; then
if command_exists zopflipng; then
zopflipng "$X" "$X"
else
pngcrush -ow "$X"
fi
elif [ ${X: -4} == '.svg' ]; then
svgo $X
else
echo "? $X" 1>&2
fi
done
#!/bin/bash
DIR=$(dirname "$0")
# TODO: probably only works on macOS
CPUS=$(sysctl -n hw.ncpu)
PROCS=$((CPUS / 2)) # run half as many tasks as CPUs
if [[ "$PROCS" == "0" ]]; then
PROCS="1"
fi
echo "Using $PROCS tasks..."
printf '%s\0' "${@}" | xargs -0 -P $PROCS -n 1 -I % bash -c "${DIR}/crush \"%\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment