使用pngcrush工具优化PNG问题
我对“pngcrush”工具有几个疑问。
在 xcode 构建过程中,
- 我将选项“压缩 PNG 文件”设置为“是”,然后检查二进制文件和图像大小。
- 然后在我的另一个构建过程中,我将选项“压缩 PNG 文件”设置为“否”,然后再次检查二进制文件和图像大小。
但是,1. 和 2. 在二进制/图像大小方面没有任何区别。
为什么“pngcrush”工具没有优化 png 文件?
任何帮助都会很棒。
提前致谢。
问候, 德文德拉
I have few queries on "pngcrush" tool.
While xcode build process,
- I am setting option "Compress PNG Files" to "YES" and then checked the binary and image size.
- 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
仅当为设备构建应用程序时才会转换文件。 iOS 模拟器获取常规 PNG。
但是,Xcode 的转换会使图像更大且加载速度更慢,因此我建议禁用
压缩 PNG 文件
选项并手动优化 PNG 图像。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.请注意,添加到 Images.xcassets 中的任何图像仍然会被压缩,无论“压缩 PNG 文件”标志如何。因此,如果您尝试为 Images.xcassets 中添加的图像保持相同的文件大小,则不可能。
现在来看看 PNGCrush,它是一个开源命令行工具,刚刚与 xcode 捆绑在一起,xcode 使用它来压缩图像。然而 pngcrush 通过清理不需要的块并重新创建 png 图像以获得最高质量来进行压缩,因此压缩后的图像可能比原始图像更高。
还有许多其他实用程序需要压缩。然而,Mac 世界的人们很幸运能够将所有工具合并为一个最佳工具。 ImageOptim 无缝集成了最佳优化工具 PNGOUT、Zopfli、Pngcrush、AdvPNG、扩展 OptiPNG、JpegOptim、jpegrescan、jpegtran 和 Gifsicle。此外,使用 Imageoptim,您在添加到应用程序之前不必再将 jpg 转换为 png,jpg 也使用 image optim 进行了优化。
要实现最佳捆绑包大小,最好执行以下操作
Clean-Build-Archive-Export 并记下 ipa 文件大小。
将“压缩 PNG 文件”设置为“否”
安装 Imageoptim(可从 http://imageoptim.com/)
转到终端并导航到源目录
使用命令
open -a ImageOptim 。
它自动查找图像源并压缩它们(不用担心也优化 .xcassets 中的图像)
现在请确保等待等待一段时间,让所有进度指示器呈红色亮起
清理并构建并存档,您将观察到生成的 ipa 文件远小于原始文件。< /p>
最后但并非最不重要的一点是,此后当您将图像添加到项目中时,请确保添加优化的图像。它就像将图像拖放到 imageOptim 中进行优化一样简单。
此外,每当添加时,请考虑将图像添加到直接在应用程序级别而不是数据级别使用的资产中。如果要添加的图像用于数据级别,请将其直接添加到项目中,并且不要为其创建资产条目,因此至少这些图像不会被破坏。
祝大家压缩愉快:)
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 :)
pngcrush 工具在将 .png 复制到应用程序包中的目标位置时由 Xcode 构建过程运行。当您将“压缩 PNG 文件”选项设置为“是”时,此过程将在您的 .png 文件上运行。 (请注意,此工具有时会增加图像的大小!)如果在 .png 图像上运行 pngcrush,我不希望它们的大小相同。
pngcrush 进程还会损坏 .png,使其只能由 iOS 打开。因此,如果您无法在应用程序包中查看图像,则这是一个好兆头,表明 pngcrush 实际上在这些图像上运行。
还有一件事要记住;有时,构建文件夹中应用程序包的内容不会直接与 Xcode 项目中的文件相对应。因此,有时手动清理构建文件夹是个好主意。
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.