Reputation: 11
I was wondering if there is a way to iteratively write png files using PyPNG (as in, row-by-row, or chunk-by-chunk) without providing the png.Writer()
with the entire data. I've looked through the documentation, but all the writer methods require all rows of the PNG at once (uses too much memory).
Thanks in advance!
Upvotes: 1
Views: 539
Reputation: 5149
If you supply an iterator, then PyPNG will use it. Full example:
#!/usr/bin/env python
import random
import png
def iter_rows():
H = 4096
for i in xrange(H):
yield [random.randrange(i+1) for _ in range(4096)]
img = png.from_array(iter_rows(), mode="L;12",
info=dict(size=(4096,4096)))
img.save("big.png")
Upvotes: 1