Skip to content

Instantly share code, notes, and snippets.

@tynn
Last active January 1, 2016 09:59
Show Gist options
  • Save tynn/8128776 to your computer and use it in GitHub Desktop.
Save tynn/8128776 to your computer and use it in GitHub Desktop.
This is a trivial pngcrush wrapper, which adds Author and Copyright tEXt chunks and removes all other chunks but tRNS and gAMA. Temporary files provide a quasi pipe and direct file modification functionality, so that '-' can be used for input and output files. By default the output file is the same like the input file.
#!/bin/sh
# 2013 CC0 http://creativecommons.org/publicdomain/zero/1.0/
# pngcrush wrapper to add Author and Copyright tEXt chunks and remove all other but tRNS and gAMA
# temporary files provide a quasi pipe and direct file modification functionality
[ $# -lt 3 ] && echo Usage: $(basename "$0") Input-File Author Copyright [Output-File] && exit 1
[ ! -f "$1" ] && ([ -t 0 ] || [ "$1" != - ]) && echo Invalid Input-File \'$1\' && exit 1 || if="$1"
[ "$if" = - ] && if=$(mktemp) && tee > "$if" && cleanup=" \"$if\""
[ $# -gt 3 ] && of="$4" || of="$1"
[ "$of" = - ] && of=$(mktemp) && cleanup="$cleanup \"$of\"" && output='cat "$of"'
[ "$if" = "$of" ] && of=$(mktemp) && output='mv "$of" "$if"'
pngcrush -rem allb -text b Author "$2" -text b Copyright "$3" "$if" "$of" && eval "$output"
[ -n "$cleanup" ] && eval "rm $cleanup"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment