Skip to content

Instantly share code, notes, and snippets.

@tynn
tynn / png-authoring.sh
Last active January 1, 2016 09:59
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"'