PNG optimization issue using pngcrush tool
Asked Answered
V

3

2

I have few queries on "pngcrush" tool.

While xcode build process,

  1. I am setting option "Compress PNG Files" to "YES" and then checked the binary and image size.
  2. Then in my another build process, I am setting option "Compress PNG Files" to "NO" and then again checked the binary and image size.

But, there is no any difference between 1. and 2. in binary/image size.

Why "pngcrush" tool is not optimizing the png files?

Any help would be great.

Thanks in advance.

Regards, Devendra

Veach answered 12/9, 2011 at 13:5 Comment(0)
N
4

Files are converted only when app is built for the device. iOS simulator gets regular PNGs.

However, Xcode's conversion can make images larger and slower to load, so I suggest disabling Compress PNG Files option and optimizing PNG images manually.

Neutralism answered 31/3, 2012 at 23:16 Comment(5)
For launch images on say a iPad, not compressing may cause iOS to burn a lot more cycles turning the image into a bit map. My opinion is to leave it on, as it defaults to YES, and assume Apple knows what they are doing. YMMV.Setback
@DavidH I've benchmarked it and Xcode-compressed images were slower to load. Bitmap conversion is trivial and embarrassingly parallel - there is no faster operation for the CPU or GPU than that (it's RAM bottlenecked). OTOH poor compression means much more data to load from disk (by several orders of magnitude slower than RAM) and much more data to decompress (decompression cannot be parallelized). I don't believe Apple knows what they're doing, e.g. on Mac they're using LZW TIFF for truecolor data!Neutralism
Did you really measure launch time on an iOS device? Using iOS routines to measure "loading" time might not accurately reflect how long some proprietary interface takes. Its just hard for me to believe Apple is doing this for no reason, and that its actually worse for your app and they don't care. Personally, I was shocked when I found out the images were larger, I think I added a bug on it (should say "Xcode Image Realignment" or something, not compression). I posted a link on a different thread that does support your asserts: imageoptim.com/tweetbot.htmlSetback
I did measure on the device (I wrote ImageOptim+ImageAlpha and the article you link to :), although I couldn't measure loading of default.png directly, but tested different ways of loading images at run time (taking care to force iOS to actually display the image rather than lazily pretending to load).Neutralism
I think I'll trust Apple to make the decision about whether their optimization is worth it for their own devices. If you chose to trust this one guy, who while an expert in PNG compression, does not work at Apple or know for sure why they apply this particular optimization, then that is your choice.Synonym
M
2

Note that any image added into Images.xcassets are still compressed irrespective of "Compress PNG Files" flag. Hence if you are trying to maintain same file sizes for images added in Images.xcassets no possibility.

Now coming to PNGCrush , its an open source command line tool just bundled along with xcode and xcode uses it to compress images with help of it. However pngcrush compresses by cleaning unwanted chunks and recreating png image for maximum quality, thus the compressed images can be higher than the originals.

There are many other utils to compress. however people in mac world are lucky to get all the tools merged into one for best. ImageOptim seamlessly integrates best optimisation tools PNGOUT, Zopfli, Pngcrush, AdvPNG, extended OptiPNG, JpegOptim, jpegrescan, jpegtran, and Gifsicle. Also with Imageoptim you dont have to anynmore convert jpg-to-png before adding to app jpgs are also optimized with image optim.

To Achieve best bundle size it is prefered to do following

  • Clean-Build-Archive-Export and note ipa file size.

  • Set "Compress PNG Files" to NO

  • Install Imageoptim (available at http://imageoptim.com/)

  • Go to terminal and navigate to source directory

  • Use command open -a ImageOptim .

  • It automatically looks into source for images and compress them (No worries optimizes images in .xcassets also)

  • Now ensure to wait for a while and let all progress indicators glow red

  • Clean and Build and Archive, You will observe resulting ipa file is far less than original.

  • Last but not least, thereafter when ever you add images into project just ensure to add the optimized ones. its as easy as dragging dropping images into imageOptim for optimization.

  • Also whenever adding consider adding images to assets which are directly used in app level but not data level. if image about to add is used in data level add it directly to project and dont create asset entry for it thus at-least those images stay out of crushing.

Happy Compressing Everyone :)

Merrifield answered 29/4, 2014 at 10:2 Comment(0)
G
1

The pngcrush tool is run by the Xcode build process when it copies the .png to its destination in the app bundle. This process is run on your .png files when you set the "Compress PNG Files" option to YES. (Be aware that this tool sometimes INCREASES the size of your images!) I would not expect the size of your .png images to be the same if pngcrush were run on them.

The pngcrush process will also mangle the .png so that it can only be opened by iOS. So if you can't view your images in the app bundle, it is a good sign that pngcrush was in fact run on them.

Another thing to keep in mind; sometimes the contents of the app bundle in the build folder will not correspond directly with your files in your Xcode project. Thus, sometimes it is a good idea to manually clean out the build folder.

Grin answered 15/2, 2012 at 0:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.