Using pngcrush with git export filter
I’d like to optimize png files when I export them (using git archive) from the repository, using a smudge filter. However, if I understand it correctly, these filters work only via STDIN and STDOUT开发者_StackOverflow社区, while pngcrush needs a “real” file.
Is there any workaround?
Use temporary files. eg:
IN=$(mktemp)
OUT=$(mktemp)
# save stdin to temp file
cat > "$IN"
# Crush the image and ignore regular output.
# Die if pngcrush fails.
pngcrush "$IN" "$OUT" > /dev/null || exit $?
# write temp file to stdout
cat "$OUT"
# clean up
rm "$IN" "$OUT" &
精彩评论