Very basic app that uses the FileLoader
component to upload an image to the server.
The server code then reads the codes in the image using pyzbar
and returns a list of the decoded data from each code.
It does work with multiple qr codes in the same image but could do with some tweaking on the image before reading it to reduce errors in reading.
https://anvil.works/build#clone:7HMZJ6G6RRYKFTKM=Y36TMMD3BXUOZQPUFUAP2PM3
7 Likes
Nice feature
Is there a way to generate QR code as well?
Not in this app but there are a few packages available in the full Python 3 environment that do it - relatively simple to do.
If you are looking to generate a QR code this may be of use - pretty agricultural but it gets the job done (needs the import statement and must be run in server code)
def get_qr_code(url, uid):
# from pyqrcode docs
code = pyqrcode.create(url, error='L', version=27, mode='binary')
file = f'/tmp/{filename}.png' # filename is just a string
code.png(file, scale=6, module_color=[0, 0, 0, 128], background=[0xff, 0xff, 0xcc])
with open(file, 'rb') as f:
media = anvil.BlobMedia('image/png', f.read(), uid)
return media
Yes, that works! Thanks for your help.