1

I generate a qr code image from an url using the python package qrcode:

url='www.google.com'
qr = qrcode.QRCode(version=1,
                   error_correction=qrcode.constants.ERROR_CORRECT_L,
                   box_size=10,
                   border=4)

qr.add_data(url)
qr.make(fit=True)
img = qr.make_image()
return img

How do I save the img to the disk at a certain path ?

I tried:

image_file = open(path_qr_code, 'w')
image_file.write(img)
image_file.close

but I get:

TypeError: write() argument must be str, not PilImage

2
  • 1
    Hint: "Not PIL Image", then you can search "how to save an PIL Image to disk". Commented Mar 5, 2019 at 17:03
  • 1
    Then I found this pillow.readthedocs.io/en/3.1.x/reference/… Commented Mar 5, 2019 at 17:04

1 Answer 1

1

TypeError: write() argument must be str, not PilImage

This indicates that img has type PilImage, then you can use the way saving a PilImage to save it. For example,

img.save(path_qr_code)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.