Fixing PNGs

June 1st, 2012

One of my hobbies is poking around in the application bundles of software that I did not write. The extent of my curiosity ranges from aiming to find the identify of an uncredited developer, to disassembling and examining the technical approaches that were taken in the code. But usually I just like to take a quick survey and see if anything catches my interest.

For Mac apps, it’s as easy as control-clicking the application in the Finder and selecting “Show Package Contents.” For iOS apps, it’s a bit tricker, but easy enough when you realize that the “.ipa” files in your Music/iTunes/Mobile Applications folder are actually zip archives and can be easily unpackaged by first changing their names to end in .zip, or by direct command line invocation:

% unzip -d Goodies "MarsEdit Touch.ipa"
% cd "Goodies/PayLoad/MarsEdit Touch.app"

At this point exploration from the Finder or Terminal is similar to browsing a Mac application, except the structure for iOS apps is a little flatter and, blast it all, none of the images are viewable. That seriously dampens my enjoyment of the bundles.

The reason most PNG images in iOS apps are not viewable is because Apple applies special, non-standard optimizations to the images to improve performance on iOS devices. This renders the images useless to all other apps that normally work with PNG files, including the Finder’s Quick Look feature.

Years ago, I discovered a handy tool called iPhonePNG that was assembled by David Watanabe. Essentially, the authors of this tool figured out the optimizations that Apple were doing, and reversed the steps to convert them back into standard PNG images. The tool relied upon a compiled-in version of the libpng library.

Recently when I went to use this tool again, I noticed that it did not work reliably. It dumped lots of memory errors and complained of “extra compressed data” in the input files. I then proceeded to spend too many hours trying to fix it, bashing my head against libpng, before my friend Tom Harrington alerted me to an Xcode-bundled tool that can do the job reliably:

iPhoneOS.platform/Developer/usr/bin/pngcrush

This Apple-modified version of the pngcrush utility accepts a “-revert-iphone-optimizations” option to do exactly the chore I’m looking to have done. But remembering the path to this tool and the long option name was not working for me, so I threw together a handy pair of zsh functions. Now when I’m bundle-surfing and want to peek at an iOS-optimized PNG, it’s easy:

% fixpng ./RedSweater.png
Writing fixed PNG to RedSweater-fixed.png
% open RedSweater-fixed.png

Or if I want to browse a whole folder full:

% fixpngs *.png

If you use zsh, or would like to adapt the functions to your preferred shell, you can download them here. Enjoy!

Updates: I was alerted by Kelvin Owers to an impressive, free tool called ImageOptim. The author argues that his optimization technique for PNGs results in smaller, faster-loading images than Apple’s, while conforming with the PNG standard. I ran some of my PNGs through the tool and it shaved 30-40% off the size. I’m going to strongly consider using this tool, and disabling Apple’s PNG optimization for my projects.

I was also informed by Jordan Breeding and Clark Cox that the “xcrun” command line tool makes a nicer method of invoking the magic Apple-customized pngcrush tool:

% xcrun -sdk iphoneos pngcrush -revert-iphone-optimizations

From the point of view of making the whole bundle-browsing process seamless, Christopher Bowns pointed me to atPeek for examining app bundles, and the associated, free Quick Look plugin for automatically decoding the PNGs.

Thanks for all the useful feedback!

The Talk Show With John Gruber

May 25th, 2012

For the past few years, John Gruber and Dan Benjamin recorded an informal, off-the-cuff-seeming podcast called The Talk Show. I didn’t listen to every episode, but I listened from the very beginning, before Dan had even founded the 5by5 network that later became its home.

I see The Talk Show’s format as the prototype for many other successful 5by5 podcasts: Dan plays the cool, somewhat disinterested straight-man to a “star,” whose own temperament, philosophies and interests ultimately define the show. After the initial success of The Talk Show, Dan threw the net wide, inviting folks such as Marco Arment, Andy Ihnatko, Merlin Mann, John Siracusa, Horace Dediu, and Jim Dalrymple to indulge audiences with their own personalities and areas of expertise. I even had the pleasure of playing the star myself on one episode of Build & Analyze.

Last week, John announced matter-of-factly that The Talk Show would no longer air on the 5by5 network, and would be joining the lineup at the fledgling Mule Radio Syndicate. Dan does a great job at 5by5 of emphasizing that the star of each show is who makes the show what it is. Nonetheless, Dan’s personality is unavoidably material to the mood and progression of these shows, so it’s safe to say that The Talk Show’s departure from 5by5 marks the end of an era.

The good news for fans of John Gruber, is it doesn’t mark the end of The Talk Show. John’s obsessive, meandering, sometimes distracted personality lives on at Mule, and I think this promises to be another great era in The Talk Show’s history. Episode 1 featured John Moltz of Crazy Apple Rumors fame, and the two delved into all the kinds of topics I’d expect. I thoroughly enjoyed the show.

I enjoyed it so much, I decided to co-sponsor this week’s episode, along with my good friends from Bare Bones Software

The Talk Show Episode #2: Dare I Say, Kubrick? 

Much to my delight, the episode turned out to feature one of my favorite “internet stars,” Mr. Adam Lisagor of Sandwich Video fame. John literally can’t go wrong if these folks are representative of the stature of future guests. So, give the new Talk Show a try, won’t you?

MarsEdit 3.5.3: Mea Culpa

May 19th, 2012

MarsEdit 3.5.3 is now available as a direct download from the MarsEdit home page. A release in the Mac App Store is pending review (Update: now available). This is a free update for licensed MarsEdit customers.

MarsEdit 3.5.2 yesterday, 3.5.3 today. Shipping subsequent updates a day apart is almost never a sign that things went the way a developer expected. In this case, I discovered a bug in MarsEdit 3.5.2 (and 3.5.1, as it happens) that would cause the blog settings editing panel in MarsEdit to fill up all of a blog’s settings with default values when you opened it to tweak a blog. Then, if you innocently click “OK”, wham, all your blog settings are updated with default settings. Not good.

So the focus on MarsEdit 3.6 was instantly sidelined, and MarsEdit 3.5.3 was brought to existence in the space of about an hour today, taking this critical bug fix and a couple other less urgent fixes that didn’t make it in time for 3.5.2.

  • Fix a serious bug that reverted blog settings to default values when opening the settings panel
  • Avoid a crash when running on a 10.6 system with older versions of Safari installed
  • Fix a rich-mode editing paste bug that could cause unwanted
    entries in HTML

I also submitted an expedited review request to the Mac App Store. Here’s hoping that will request in a shorter wait time for Mac App Store customers. Please note however that if you own the Mac App Store edition of any of my apps, you are also entitled to download and run the direct-sale versions from my site without limitation.

MarsEdit 3.5.2: Character Count

May 18th, 2012

MarsEdit 3.5.2 is now available on the Mac App Store and directly from the Red Sweater Store. This is a free update for licensed MarsEdit customers.

Mostly just another batch of bug fixes here, but I snuck in one small feature-tweak that should please writers in character-based languages and authors who aim for character-based writing goals rather than word-based.

If you weren’t aware of MarsEdit’s live-updated word count feature, it’s located in the “Status Bar”, which you can activate by selecting View -> Show Status Bar. Here is an example of how it looks when editing a post in MarsEdit 3.5.2:

Screenshot of the MarsEdit word and character count status indicator.

Here’s the complete list of changes for this release:

MarsEdit 3.5.2

  • Status bar in post editor now includes character count along with word count
  • Restore ability to paste HTML with “embed” tags in the Rich Editor
  • Restore expected list manipulation behavior with tab and return keys
  • Fix a crash that occurred when editing a Tumblr quotation post with no attribution
  • Work around issue with WordPress pages showing up as empty posts if not permitted to edit
  • Fix autoconfiguration of IBM Lotus Connections blogs
  • Fix the scrolling behavior of custom fields text input

Onward to MarsEdit 3.6!