开发者

Using pngcrush with git export filter

开发者 https://www.devze.com 2023-02-01 01:50 出处:网络
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开

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" &
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号