Python Forum
.png data as matrix ? - Printable Version

+- Python Forum (
+-- Forum: Python Coding (
+--- Forum: General Coding Help (
+--- Thread: .png data as matrix ? (/thread-26432.html)

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


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?


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 ="qr.png", "r")
>>> qr.size
(171, 171)
>>> 171 * 171
>>> len(list(qr.getdata()))

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

Perfect! Thanks.

Brian H.