component_label.py 1.1 KB

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