Batch optimization of PNGs for iphone/ipad display

2019-02-07 07:32发布

I'm working on a magazine viewer for ipad and I'm struggling with the performance.

I figured out that the most expensive part of displaying the pngs is the loading process. I know that xcode is able to optimize pngs during the build and such images are loaded much faster. But I can't include all images in to the build as it will be huge.

Do you know how to optimize an arbitrary png without including it in the build process?

Do you know what is the best format for iphone? I think that pngs should use RGB-8888 color scheme but I'm not sure what else is important.

Maybe you know exact params for imagemagick?

7条回答
劫难
2楼-- · 2019-02-07 07:39

I think I've found a good article about png optimization for iphone: http://iphonedevelopment.blogspot.com/2008/10/iphone-optimized-pngs.html

It seams that xcode uses this command: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/iphoneos-optimize

It appears that the above command uses a modified version of pngcrush to optimize pngs and transform the color channels: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush -iphone -f 0 orig.png optimized.png

And the optimization is really helpful. I've got 5 time faster image loading!

查看更多
做个烂人
3楼-- · 2019-02-07 07:43

I have been experimenting with pngnq, pngquant, pngcrush, optipng, etc.

For my set of PNGs, I've achieved minimum file size with pngquant, pngnq and pngcrush

Dir.glob("**/*.png").each do |file|
  ['pngnq -e .png -f', 'pngquant -f -speed 1 -ext .png', 'pngcrush'].each do |command|
    puts "#{command} #{file}"
    `#{command} #{file}`
  end
end

More details at: http://l4u.github.com/blog/2012/04/02/optimizing-file-sizes-of-png-images/

查看更多
姐就是有狂的资本
4楼-- · 2019-02-07 07:45

Try http://texturepacker.com

It can not only optimize PNGs but also reduce colors e.g. to RGBA4444 or RGB565 which decreases ping size dramatically and improves rendering on the devices.

You could also export PVR files for devices that support it (e.g. iOS, some Android)

And it also supports scaling down images for low res devices.

查看更多
做自己的国王
5楼-- · 2019-02-07 07:55

In my benchmark file size turned out to be more important than Xcode preprocessing (Xcode files were larger and slower to load).

Best way to reduce PNG file size is to convert it to PNG8+alpha format — you can do that in batch with pngquant (or tweak manually with GUI).

However, if in your case conversion from RGBA to premultiplied BGRA is what is taking the most time, then a fork of AdvanceCOMP with XCode proprietary extensions added will let you batch convert PNGs to iOS's native format.

查看更多
Root(大扎)
6楼-- · 2019-02-07 07:56

I've lots and lots of space using pngnq, but I haven't done any testing to see if decoding the image slows it down at all.

查看更多
Bombasti
7楼-- · 2019-02-07 07:59

The best results I know of are achieved with ImageOptim, which I use myself for PNGs that are not deployed via Xcode. It uses pngcrush and some other PNG optimization tools to achieve best compression. As far as I know, it doesn't employ alpha premultiplication and byte swapping though. ImageOptim also has a nice GUI with drag-and-drop support and can crush multiple files simultaneously.

查看更多
登录 后发表回答