Skip to content

Commit

Permalink
Add fixpng.sh for convenient fixing of iOS-optimized PNGs.
Browse files Browse the repository at this point in the history
  • Loading branch information
atomicbird committed Jun 2, 2012
1 parent 2758992 commit e8f095f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
@@ -1,13 +1,15 @@
# Atomic Tools

A collection of useful Objective-C code. Most of this has been blogged about at [Cocoa is my Girlfriend](http://www.cimgf.com/).
A collection of useful Objective-C code and other items of use to iOS and Mac OS X developers. Most of this has been blogged about at [Cocoa is my Girlfriend](http://www.cimgf.com/).

* `NSObject+setValuesForKeysWithJSONDictionary.h`: Safer alternative to `setValuesForKeysWithDictionary:` for use when importing JSON. Works with any object with declared properties corresponding to JSON dictionary keys. Detailed discussion is at [CIMGF](http://www.cimgf.com/2012/01/11/handling-incoming-json-redux/).

* `NSObject+deallocBlock.h`: Add a block to any object that will execute when that object is deallocated. Described in detail at [CIMGF](http://www.cimgf.com/2012/02/17/extending-nsdata-and-not-overriding-dealloc/).

* `NSData+reallyMapped.h`: Create an NSData object using a memory mapped file. Works even though `dataWithContentsOfMappedFile:` is deprecated in iOS 5.0 and `NSDataReadingMappedAlways` doesn't always (despite the name) create memory mapped instances. Described in detail at [CIMGF](http://www.cimgf.com/2012/02/17/extending-nsdata-and-not-overriding-dealloc/).

* `fixpng.sh`: Two shell functions useful for converting iOS-optimized PNGs back into standard PNGs. These functions rely on the `xcrun` command-line tool and probably require that Xcode 4.3 or higher be installed.

# Important note

All code in this repository is designed for use with automated reference counting (ARC). If you are not using ARC you may experience memory leaks or worse.
All Objective-C code in this repository is designed for use with automated reference counting (ARC). If you are not using ARC you may experience memory leaks or worse.
40 changes: 40 additions & 0 deletions fixpng.sh
@@ -0,0 +1,40 @@
# Fix an iOS-converted PNG
# By Tom Harrington, June 1 2012.

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

}

0 comments on commit e8f095f

Please sign in to comment.