forked from emilevs/label_printer
Working gen_image
This commit is contained in:
parent
a6163cff0a
commit
2a81b7efde
3 changed files with 31 additions and 0 deletions
BIN
flask/ComicMono.ttf
Normal file
BIN
flask/ComicMono.ttf
Normal file
Binary file not shown.
30
flask/gen_image.py
Normal file
30
flask/gen_image.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from PIL import Image, ImageDraw, ImageFont
|
||||
from colorama import Fore, Style
|
||||
from printer_info import *
|
||||
|
||||
def gen_image(height, string1, string1_size, string1_pos, string2, string2_size, string2_pos, justification):
|
||||
font1 = ImageFont.truetype("ComicMono.ttf", size=string1_size)
|
||||
font2 = ImageFont.truetype("ComicMono.ttf", size=string2_size)
|
||||
|
||||
text1_box = font1.getbbox(string1)
|
||||
text2_box = font2.getbbox(string2)
|
||||
|
||||
text1_width = text1_box[2]
|
||||
text2_width = text2_box[2]
|
||||
|
||||
# I am assuming the left corner of the bbox to always be 0, I have yet to
|
||||
# encounter a situation when this isn't the case
|
||||
if (text1_box[0] != 0 or text2_box[0] != 0):
|
||||
print(Fore.YELLOW + "Warning, found situation where left corner of bbox of text != 0,", "text1_box:", text1_box, "text2_box", text2_box)
|
||||
|
||||
|
||||
img = Image.new('1', (max(text1_width, text2_width), height), color=1)
|
||||
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
draw.text((0, string1_pos), string1, font=font1)
|
||||
draw.text((0, string2_pos), string2, font=font2)
|
||||
|
||||
return img
|
||||
|
||||
gen_image(label_width, "faf", 30, 10, "Hello world", 20, 40, justification="left").save('output.png')
|
1
flask/printer_info.py
Normal file
1
flask/printer_info.py
Normal file
|
@ -0,0 +1 @@
|
|||
label_width = 100
|
Loading…
Reference in a new issue