dynamic text layout, outline box
This commit is contained in:
parent
fdb148949a
commit
963114b37a
50
layouter.py
50
layouter.py
|
@ -99,9 +99,42 @@ def format_to_printable(drive):
|
|||
cut_string(30, datetime.datetime.utcfromtimestamp(drive.shred_timestamp).strftime('%Y-%m-%d %H:%M:%S')),\
|
||||
cut_string(30, str(datetime.timedelta(seconds = drive.shred_duration))))
|
||||
|
||||
def draw_text(drawable, printable_data, text_y_offset):
|
||||
font_file = get_font_path()
|
||||
font_size = 20
|
||||
text_x_offset = 10
|
||||
text_x_offset_increment = 25
|
||||
|
||||
drawable.text((text_y_offset, text_x_offset), "Familiy: " + printable_data.modelfamiliy,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
text_x_offset += text_x_offset_increment
|
||||
drawable.text((text_y_offset, text_x_offset), "Model: " + printable_data.modelname,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
text_x_offset += text_x_offset_increment
|
||||
drawable.text((text_y_offset, text_x_offset), "Serial: " + printable_data.serialnumber,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
text_x_offset += text_x_offset_increment
|
||||
drawable.text((text_y_offset, text_x_offset), "Hours: " + printable_data.power_on_hours,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
text_x_offset += text_x_offset_increment
|
||||
drawable.text((text_y_offset, text_x_offset), "Cycles: " + printable_data.power_cycle,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
text_x_offset += text_x_offset_increment
|
||||
drawable.text((text_y_offset, text_x_offset), "Errors: " + printable_data.smart_error_count,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
text_x_offset += text_x_offset_increment
|
||||
drawable.text((text_y_offset, text_x_offset), "Shred on: " + printable_data.shred_timestamp,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
text_x_offset += text_x_offset_increment
|
||||
drawable.text((text_y_offset, text_x_offset), "Duration: " + printable_data.shred_duration,(0),font=ImageFont.truetype(font_file, font_size))
|
||||
text_x_offset += text_x_offset_increment
|
||||
|
||||
def draw_outline(drawable, margin, width, output_width, output_height):
|
||||
#upper
|
||||
drawable.line([(margin,margin), (output_width -margin ,margin)], fill=None, width=width, joint=None)
|
||||
#left
|
||||
drawable.line([(margin,margin), (margin ,output_height-margin)], fill=None, width=width, joint=None)
|
||||
#right
|
||||
drawable.line([(output_width-margin,margin), (output_width-margin ,output_height-margin)], fill=None, width=width, joint=None)
|
||||
#lower
|
||||
drawable.line([(margin,output_height - margin), (output_width-margin,output_height -margin)], fill=None, width=width, joint=None)
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
output_width = 696
|
||||
output_height = 348
|
||||
|
||||
|
@ -112,19 +145,12 @@ def main():
|
|||
text_y_offset= int(output_width / 3)
|
||||
|
||||
output_image = Image.new('1', (output_width, output_height), "white")
|
||||
font_file = get_font_path()
|
||||
|
||||
draw = ImageDraw.Draw(output_image)
|
||||
|
||||
|
||||
draw.text((text_y_offset, 5), "modelfamiliy: " + printable_data.modelfamiliy,(0),font=ImageFont.truetype(font_file, 15))
|
||||
draw.text((text_y_offset, 20), "modelname: " + printable_data.modelname,(0),font=ImageFont.truetype(font_file, 15))
|
||||
draw.text((text_y_offset, 35), "serial: " + printable_data.serialnumber,(0),font=ImageFont.truetype(font_file, 15))
|
||||
draw.text((text_y_offset, 50), "poweronhours: " + printable_data.power_on_hours,(0),font=ImageFont.truetype(font_file, 15))
|
||||
draw.text((text_y_offset, 65), "powercycle: " + printable_data.power_cycle,(0),font=ImageFont.truetype(font_file, 15))
|
||||
draw.text((text_y_offset, 80), "errorcount: " + printable_data.smart_error_count,(0),font=ImageFont.truetype(font_file, 15))
|
||||
draw.text((text_y_offset, 95), "shredtimestamp: " + printable_data.shred_timestamp,(0),font=ImageFont.truetype(font_file, 15))
|
||||
draw.text((text_y_offset, 110), "shredduration: " + printable_data.shred_duration,(0),font=ImageFont.truetype(font_file, 15))
|
||||
draw_outline(draw, 4, 5, output_width, output_height)
|
||||
|
||||
|
||||
draw_text(draw, printable_data, text_y_offset)
|
||||
|
||||
|
||||
output_image.save("output.png")
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
Loading…
Reference in New Issue