public
Created

Zsh functions for easily "fixing" iOS-optimized PNG files

  • Download Gist
gistfile1.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
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
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.