Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add fixpng.sh for convenient fixing of iOS-optimized PNGs.

  • Loading branch information...
commit e8f095f33c39204963ebe74bced8d955f8176688 1 parent 2758992
Tom Harrington authored

Showing 2 changed files with 44 additions and 2 deletions. Show diff stats Hide diff stats

  1. +4 2 README.md
  2. +40 0 fixpng.sh
6 README.md
Source Rendered
... ... @@ -1,6 +1,6 @@
1 1 # Atomic Tools
2 2
3   -A collection of useful Objective-C code. Most of this has been blogged about at [Cocoa is my Girlfriend](http://www.cimgf.com/).
  3 +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/).
4 4
5 5 * `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/).
6 6
@@ -8,6 +8,8 @@ A collection of useful Objective-C code. Most of this has been blogged about at
8 8
9 9 * `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/).
10 10
  11 +* `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.
  12 +
11 13 # Important note
12 14
13   -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.
  15 +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 fixpng.sh
... ... @@ -0,0 +1,40 @@
  1 +# Fix an iOS-converted PNG
  2 +# By Tom Harrington, June 1 2012.
  3 +
  4 +fixpng () {
  5 + if [ -z "$1" ]; then
  6 + echo "Usage: fixpng <inputFile> [outputFile]"
  7 + return -1
  8 + else
  9 + inputFile=$1
  10 +
  11 + # Only "png" and "PNG" are allowed
  12 + pngRegex='.*.(png|PNG)$'
  13 + if [[ $inputFile =~ $pngRegex ]]; then
  14 + if [ -n "$2" ]; then
  15 + # Use whatever name was provided
  16 + outputFile=$2
  17 + else
  18 + # Generate a filename, preserve file extension case.
  19 + extension=${BASH_REMATCH[1]}
  20 + outputFile=${inputFile%.$extension}-fixed.$extension
  21 + fi
  22 + echo "Converting $inputFile to $outputFile"
  23 +
  24 + xcrun -sdk iphoneos pngcrush -q -revert-iphone-optimizations $inputFile $outputFile
  25 + else
  26 + echo "Skipping $inputFile since it's not a png"
  27 + fi
  28 + fi
  29 +}
  30 +
  31 +# Fix a whole mess of pngs at once
  32 +fixpngs () {
  33 + if [ -z "$1" ]; then
  34 + echo "Usage: fixpng <inputFiles> [outputFile]"
  35 + return -1
  36 + else
  37 + for file in "$@"; do fixpng $file; done
  38 + fi
  39 +
  40 +}

0 comments on commit e8f095f

Please sign in to comment.
Something went wrong with that request. Please try again.