Last active
June 6, 2019 05:00
-
-
Save samthor/f19290225a763c2df13bd48f1915dee8 to your computer and use it in GitHub Desktop.
Helpers to compress PNG images
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 | |
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 |
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 | |
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