talofer99

python get b64 data

Oct 21st, 2021
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import qrcode
  2. from PIL import Image
  3. import os
  4. import base64
  5.  
  6. welcomeCode = "0A1B2C"
  7. fileNamePng = "qr_" + welcomeCode + ".png"
  8.  
  9. # create QR
  10. img = qrcode.make(welcomeCode)
  11. type(img)  # qrcode.image.pil.PilImage
  12. # resize
  13. newImage = img.resize((73, 73))
  14. #save and reopen
  15. newImage.save(fileNamePng)
  16.  
  17. with open(fileNamePng, "rb") as img_file:
  18.     b64_string = base64.b64encode(img_file.read())
  19. print(b64_string.decode('utf-8'))
  20.  
Add Comment
Please, Sign In to add comment