Skip to content

Instantly share code, notes, and snippets.

@samthor samthor/crush

Last active Jun 6, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.