PNG optimization issue using pngcrush tool

你。 提交于 2020-01-23 15:44:13

问题


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


回答1:


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.




回答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 :)




回答3:


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.



来源:https://stackoverflow.com/questions/7388324/png-optimization-issue-using-pngcrush-tool

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!