25 lines
1.1 KiB
Python
25 lines
1.1 KiB
Python
from .label_image import Label
|
|
import qrcode
|
|
|
|
class ComponentLabel(Label):
|
|
pixels_x = 991
|
|
pixels_y = 306
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def put_content(self, qr_data, component_name, manufacturer, package):
|
|
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)
|
|
self.draw_text(manufacturer, 320, self.pixels_y/2, size=32, font_file='bold', scale_to_fit=True, centered_x=False, centered_y=True)
|
|
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)
|
|
qr = qrcode.QRCode(
|
|
version=1,
|
|
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
|
box_size=8,
|
|
border=0,
|
|
)
|
|
qr.add_data(qr_data)
|
|
qr.make(fit=True)
|
|
qr_image = qr.make_image(fill_color="black", back_color="white")
|
|
qr_y_size = qr_image.size[1]
|
|
self.img.paste(qr_image, box=(0, int(self.pixels_y/2 - qr_y_size/2))) |