Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fixpng.sh for convenient fixing of iOS-optimized PNGs.
- Loading branch information
1 parent
2758992
commit e8f095f
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
} |