Closed KmolYuan closed 1 year ago
@KmolYuan I couldn't run the code example you provided. Can you provide a working example with only Numpy without PyQt5?
I'm sorry for the horrible things I once wrote.
The returned image
can be used as a normal numpy array with size w x w x 3
.
>>> import qrcode
>>> from qrcode.image.numpy import NpImage
>>> image = qrcode.make("example", image_factory=NpImage)
>>> image.shape
(290, 290, 3)
>>> image[0, 0]
array([255, 255, 255], dtype=uint8)
>>> from numpy import array
>>> array(image) # Convert to np.array
array([[[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
...,
[255, 255, 255],
[255, 255, 255],
[255, 255, 255]]], dtype=uint8)
@KmolYuan thank you for the updates! I was able to test this locally.
I'm still not sure about this PR, though. The save
method is not implemented and there's no way to actually see an image and scan it. If there's a use case for this factory, it can always be shipped as a separate package, but I think it needs a minimum compatibility with the default interface to be included in the package.
If necessary, I can use a pure python function to achieve.
import qrcode
from qrcode.image.numpy import NpImage
image = qrcode.make("example", image_factory=NpImage)
image.save("example.png")
@KmolYuan I fixed the save method to be able to save to a stream and added a test, but we'd need more test for this factory as it breaks the coverage tests (under 98%). Could you make sure we have more test coverage for this?
Simplified to gray-scale, same as PIL image.
Hello! This is a image factory for NumPy array. (for NumPy and OpenCV users)