better styling with font
This commit is contained in:
parent
ea0767a220
commit
b16d72415e
52
layouter.py
52
layouter.py
|
@ -68,11 +68,16 @@ class DriveDataJson:
|
|||
rehdd_info = ReHddInfo("https://git.mosad.xyz/localhorst/reHDD", "bV0.2.2") # read this from rehdd process
|
||||
|
||||
temp_drive = DriveData(drive_index=0, drive_state="shredded", modelfamiliy="Toshiba 2.5\\ HDD MK..65GSSX",\
|
||||
modelname="TOSHIBA MK3265GSDX", capacity=343597383680, serialnumber="YG6742U56UDRL", power_on_hours=7074,\
|
||||
modelname="TOSHIBA MK3265GSDX", capacity=343597383680, serialnumber="YG6742U56UDRL123", power_on_hours=7074,\
|
||||
power_cycle=4792, smart_error_count=1, shred_timestamp=1647937421, shred_duration=81718)
|
||||
|
||||
|
||||
def get_font_path():
|
||||
def get_font_path_regular():
|
||||
path = "/usr/share/fonts"
|
||||
files = glob.glob(path + "/**/DejaVuSans.ttf", recursive = True)
|
||||
return files[0]
|
||||
|
||||
def get_font_path_bold():
|
||||
path = "/usr/share/fonts"
|
||||
files = glob.glob(path + "/**/DejaVuSans-Bold.ttf", recursive = True)
|
||||
return files[0]
|
||||
|
@ -105,10 +110,11 @@ def format_to_printable(drive):
|
|||
#print(cut_string(30, datetime.datetime.utcfromtimestamp(drive.shred_timestamp).strftime('%Y-%m-%d %H:%M:%S')))
|
||||
#print(cut_string(30, str(datetime.timedelta(seconds = drive.shred_duration))))
|
||||
|
||||
return DriveDataPrintable(cut_string(20, re.sub(r"[^a-zA-Z0-9. ]", "", drive.modelfamiliy)),\
|
||||
return DriveDataPrintable(
|
||||
cut_string(20, re.sub(r"[^a-zA-Z0-9. ]", "", drive.modelfamiliy)),\
|
||||
cut_string(20, re.sub(r"[^a-zA-Z0-9. ]", "", drive.modelname)),\
|
||||
cut_string(20, human_readable_capacity(drive.capacity)),\
|
||||
cut_string(20, re.sub(r"[^a-zA-Z0-9.-_]", "", drive.serialnumber)),\
|
||||
cut_string(16, re.sub(r"[^a-zA-Z0-9.-_]", "", drive.serialnumber)),\
|
||||
cut_string(30, human_readable_power_on_hours(drive.power_on_hours)),\
|
||||
cut_string(10, str(drive.power_cycle)),\
|
||||
cut_string(10, str(drive.smart_error_count)),\
|
||||
|
@ -116,29 +122,39 @@ def format_to_printable(drive):
|
|||
cut_string(30, str(datetime.timedelta(seconds = drive.shred_duration))))
|
||||
|
||||
def draw_text(drawable, printable_data, text_x_offset):
|
||||
font_file = get_font_path()
|
||||
font_file_regular = get_font_path_regular()
|
||||
font_file_bold = get_font_path_bold()
|
||||
font_size = 20
|
||||
text_y_offset = 15
|
||||
text_y_offset = 10
|
||||
text_y_offset_increment = 25
|
||||
value_colum_x_offset = 120
|
||||
|
||||
drawable.text((text_x_offset, text_y_offset), "Familiy: " + printable_data.modelfamiliy,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
drawable.text((text_x_offset, text_y_offset), printable_data.serialnumber,(0),font=ImageFont.truetype(font_file_bold, 30))
|
||||
text_y_offset += 40
|
||||
|
||||
drawable.text((text_x_offset, text_y_offset), "Familiy: ",(0),font=ImageFont.truetype(font_file_bold, font_size))
|
||||
drawable.text((text_x_offset+value_colum_x_offset, text_y_offset), printable_data.modelfamiliy,(0),font=ImageFont.truetype(font_file_regular, font_size))
|
||||
text_y_offset += text_y_offset_increment
|
||||
drawable.text((text_x_offset, text_y_offset), "Model: " + printable_data.modelname,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
drawable.text((text_x_offset, text_y_offset), "Model: ",(0),font=ImageFont.truetype(font_file_bold, font_size))
|
||||
drawable.text((text_x_offset+value_colum_x_offset, text_y_offset), printable_data.modelname,(0),font=ImageFont.truetype(font_file_regular, font_size))
|
||||
text_y_offset += text_y_offset_increment
|
||||
drawable.text((text_x_offset, text_y_offset), "Serial: " + printable_data.serialnumber,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
drawable.text((text_x_offset, text_y_offset), "Hours: " ,(0),font=ImageFont.truetype(font_file_bold, font_size))
|
||||
drawable.text((text_x_offset+value_colum_x_offset, text_y_offset), printable_data.power_on_hours,(0),font=ImageFont.truetype(font_file_regular, font_size))
|
||||
text_y_offset += text_y_offset_increment
|
||||
drawable.text((text_x_offset, text_y_offset), "Hours: " + printable_data.power_on_hours,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
drawable.text((text_x_offset, text_y_offset), "Cycles: ",(0),font=ImageFont.truetype(font_file_bold, font_size))
|
||||
drawable.text((text_x_offset+value_colum_x_offset, text_y_offset), printable_data.power_cycle,(0),font=ImageFont.truetype(font_file_regular, font_size))
|
||||
text_y_offset += text_y_offset_increment
|
||||
drawable.text((text_x_offset, text_y_offset), "Cycles: " + printable_data.power_cycle,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
drawable.text((text_x_offset, text_y_offset), "Errors: ", (0),font=ImageFont.truetype(font_file_bold, font_size))
|
||||
drawable.text((text_x_offset+value_colum_x_offset, text_y_offset), printable_data.smart_error_count,(0),font=ImageFont.truetype(font_file_regular, font_size))
|
||||
text_y_offset += text_y_offset_increment
|
||||
drawable.text((text_x_offset, text_y_offset), "Errors: " + printable_data.smart_error_count,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
drawable.text((text_x_offset, text_y_offset), "Shred on: ",(0),font=ImageFont.truetype(font_file_bold, font_size))
|
||||
drawable.text((text_x_offset+value_colum_x_offset, text_y_offset), printable_data.shred_timestamp,(0),font=ImageFont.truetype(font_file_regular, font_size))
|
||||
text_y_offset += text_y_offset_increment
|
||||
drawable.text((text_x_offset, text_y_offset), "Shred on: " + printable_data.shred_timestamp,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
text_y_offset += text_y_offset_increment
|
||||
drawable.text((text_x_offset, text_y_offset), "Duration: " + printable_data.shred_duration,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
drawable.text((text_x_offset, text_y_offset), "Duration: " ,(0),font=ImageFont.truetype(font_file_bold, font_size))
|
||||
drawable.text((text_x_offset+value_colum_x_offset, text_y_offset), printable_data.shred_duration,(0),font=ImageFont.truetype(font_file_regular, font_size))
|
||||
text_y_offset += text_y_offset_increment
|
||||
|
||||
drawable.text((text_x_offset, text_y_offset), printable_data.capacity,(0),font=ImageFont.truetype(font_file, font_size*3))
|
||||
drawable.text((text_x_offset, text_y_offset), printable_data.capacity,(0),font=ImageFont.truetype(font_file_bold, font_size*3))
|
||||
|
||||
def draw_outline(drawable, margin, width, output_width, output_height):
|
||||
#upper
|
||||
|
@ -152,7 +168,7 @@ def draw_outline(drawable, margin, width, output_width, output_height):
|
|||
|
||||
def draw_qr_code(image, data):
|
||||
qr_img = qrcode.make(data)
|
||||
qr_img.thumbnail((290, 290), Image.Resampling.LANCZOS)
|
||||
qr_img.thumbnail((291, 291), Image.Resampling.LANCZOS)
|
||||
image.paste(qr_img, (7, 7))
|
||||
|
||||
|
||||
|
@ -172,7 +188,7 @@ def main():
|
|||
output_image = Image.new('1', (output_width, output_height), "white")
|
||||
draw = ImageDraw.Draw(output_image)
|
||||
|
||||
draw_outline(draw, 2, 5, output_width, output_height)
|
||||
draw_outline(draw, 1, 4, output_width, output_height)
|
||||
draw_text(draw, printable_data, text_x_offset)
|
||||
draw_qr_code(output_image, str(json_qr_daten).replace(" ", ""))
|
||||
|
||||
|
|
BIN
output.png
BIN
output.png
Binary file not shown.
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.5 KiB |
Loading…
Reference in New Issue