public
Created

Bash functions for easily "fixing" iOS-optimized PNG files (based on https://gist.github.com/2854083)

  • Download Gist
fixpng.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 34 35 36 37 38
# Fix an iOS-converted PNG
fixpng () {
if [ -z "$1" ]; then
echo "Usage: fixpng <inputFile> [outputFile]"
return -1
else
inputFile=$1
# Only "png" and "PNG" are allowed
pngRegex='.*.(png|PNG)$'
if [[ $inputFile =~ $pngRegex ]]; then
if [ -n "$2" ]; then
# Use whatever name was provided
outputFile=$2
else
# Generate a filename, preserve file extension case.
extension=${BASH_REMATCH[1]}
outputFile=${inputFile%.$extension}-fixed.$extension
fi
echo "Converting $inputFile to $outputFile"
xcrun -sdk iphoneos pngcrush -q -revert-iphone-optimizations $inputFile $outputFile
else
echo "Skipping $inputFile since it's not a png"
fi
fi
}
 
# Fix a whole mess of pngs at once
fixpngs () {
if [ -z "$1" ]; then
echo "Usage: fixpng <inputFiles> [outputFile]"
return -1
else
for file in "$@"; do fixpng $file; done
fi
 
}

These functions are now in my atomictools repository.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.