lincolnloop / python-qrcode

Python QR Code image generator
https://pypi.python.org/pypi/qrcode
Other
4.34k stars 664 forks source link

Saving image #258

Closed Rohit685 closed 2 years ago

Rohit685 commented 2 years ago
temp_filename = "myqr.png"
qr.add_data(QRUrl)
qr.make(fit=True)
img = qr.make_image()
img.save(temp_filename)

I am trying to save this image to my static folder. Can you do this using the .save() function? If so, how? If not, what are some other options I could save it?

Thanks

SmileyChris commented 2 years ago

I'm guessing you're using Django. So something like this:

from qrcode import make
from django.contrib.staticfiles.storage import staticfiles_storage

qr = make(QRUrl)
with staticfiles_storage.open('myqr.png') as f:
    qr.save(f)