Skip to content

Instantly share code, notes, and snippets.

@gongbin
Forked from danielpunkass/gist:2854083
Created June 10, 2012 01:15
Show Gist options
  • Save gongbin/2903414 to your computer and use it in GitHub Desktop.
Save gongbin/2903414 to your computer and use it in GitHub Desktop.
Zsh functions for easily "fixing" iOS-optimized PNG files
function fixpng ()
{
if [[ ! -f $1 ]] ; then
echo "Usage: fixpng <inputFiles> [outputFile]"
return -1
else
local inputFile=$1
local outputFile=$1
if [[ -e $2 ]] ; then
outputFile=$2
else
zmodload zsh/regex
local baseName=$1
[[ $inputFile -regex-match "^(.*).png" ]] && baseName=$match[1]
outputFile=$baseName-fixed.png
fi
echo Writing fixed PNG to $outputFile
"`xcode-select -print-path`/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush" -q -revert-iphone-optimizations $inputFile $outputFile
fi
}
# Fix a whole mess of pngs at once
fixpngs ()
{
if [[ ! -f $1 ]] ; then
echo "Usage: fixpng <inputFiles> [outputFile]"
return -1
else
for i in "$@"; do fixpng ./"$i"; done;
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment