How to combine multiple PNGs into one big PNG file?

后端 未结 9 2034
天涯浪人
天涯浪人 2020-11-28 08:26

I have approx. 6000 PNG files (256*256 pixels) and want to combine them into a big PNG holding all of them programmatically.

What\'s the best/fastest way to do that?

9条回答
  •  难免孤独
    2020-11-28 09:20

    The PNG format has no support for tiling, so there is no way you can escape at least decompressing and recompressing the data stream. If the palettes of all images are identical (or all absent), this is the only thing you really need to do. (I'm also assuming the images aren't interlaced.)

    You could do this in a streaming way, only having open one "row" of PNGs at a time, reading appropriately-sized chunks from their data stream and writing them to the output stream. This way you would not need to keep entire images in memory. The most efficient way would be to program this on top of libpng yourself. You may need to keep slightly more than one scanline of pixels in memory because of the pixel prediction.

    But just using the command-line utilities of ImageMagick, netpbm or similar will save you a large amount of development time for what may be little gain.

提交回复
热议问题