Skip to content

Instantly share code, notes, and snippets.

@atomicbird
Created June 2, 2012 00:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomicbird/2855867 to your computer and use it in GitHub Desktop.
Save atomicbird/2855867 to your computer and use it in GitHub Desktop.
Bash functions for easily "fixing" iOS-optimized PNG files (based on https://gist.github.com/2854083)
# 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
}
@atomicbird
Copy link
Author

These functions are now in my atomictools repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment