Skip to content

@atomicbird /fixpng.sh
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Owner

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
Something went wrong with that request. Please try again.