Python Forum

Full Version: .png data as matrix ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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
Perfect! Thanks.

Brian H.