Source

small_scripts / pngcrushgamma.sh

#!/bin/sh

MYNAME=`basename "$0"`

print_help() {
	cat << EOF
Usage: $MYNAME [-v] file [ files... ]

This script will call pngcrush to remove gAMA chunk from PNG files, so that
they will look fine inside Internet Explorer.

In addition, other color-related chunks are also removed: cHRM, iCCP, sRGB

Option:
  -v     verbose mode

Read more:
http://morris-photographics.com/photoshop/articles/png-gamma.html
http://snook.ca/archives/design/which_image_for/#c21159
http://www.hanselman.com/blog/GammaCorrectionAndColorCorrectionPNGIsStillTooHard.aspx
EOF
}


if [ -z "$1"  -o  "$1" = "-h"  -o  "$1" = "--help"  ] ; then
	print_help
	exit 1
fi

VERBOSE=0
if [ "$1" = "-v" ] ; then
	VERBOSE=1
	shift
fi


if [ "$VERBOSE" = 1 ] ; then
	PARAM=""
else
	PARAM="-q"
fi

for i in "$@" ; do
	TMPFILE=`mktemp`
	pngcrush $PARAM -rem cHRM -rem gAMA -rem iCCP -rem sRGB "$i" "$TMPFILE"
	# Damn pngcrush that does not correctly return an useful exit code
	# -s FILE        True if file exists and is not empty.
	if [ -s "$TMPFILE" ] ; then
		echo "Updated file '$i'."
		cat "$TMPFILE" > "$i"
	else
		echo "File '$i' was not changed."
	fi
	rm -f "$TMPFILE"
done
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.