storage_label.py 766 B

1234567891011121314151617181920212223
  1. from .label_image import Label
  2. import qrcode
  3. class StorageLabel(Label):
  4. pixels_x = 991
  5. pixels_y = 306
  6. def __init__(self):
  7. super().__init__()
  8. def put_content(self, qr_data, storage_name):
  9. self.draw_text(storage_name, 320, self.pixels_y/2, size=32, font_file='bold', scale_to_fit=True, centered_x=False, centered_y=True)
  10. qr = qrcode.QRCode(
  11. version=1,
  12. error_correction=qrcode.constants.ERROR_CORRECT_L,
  13. box_size=8,
  14. border=0,
  15. )
  16. qr.add_data(qr_data)
  17. qr.make(fit=True)
  18. qr_image = qr.make_image(fill_color="black", back_color="white")
  19. qr_y_size = qr_image.size[1]
  20. self.img.paste(qr_image, box=(0, int(self.pixels_y/2 - qr_y_size/2)))