Python Forum
.png data as matrix ? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: .png data as matrix ? (/thread-26432.html)



.png data as matrix ? - Hambonius - May-01-2020

Hi,

What is the best python3 strategy for extracting the data chunk from a small monochrome .png file, representing a QR code? Ultimately, I want to print it serially, pixel line by pixel line, to a dumb serial label printer. I am thinking I need to extract the data field as a matrix to feed to the print routine.

Thoughts / suggestions?

Thanks,

Brian H.


RE: .png data as matrix ? - bowlofred - May-01-2020

I'd probably use pillow. Can install with pip.

>>> from PIL import Image
>>> qr = Image.open("qr.png", "r")
>>> qr.size
(171, 171)
>>> 171 * 171
29241
>>> len(list(qr.getdata()))
29241



RE: .png data as matrix ? - Hambonius - May-02-2020

Perfect! Thanks.

Brian H.