Skip to content

Commit

Permalink
FEAT - default font size was small
Browse files Browse the repository at this point in the history
Try dejavuSans with size 20, if not available (comes with matplotlib) - fallback to default font without the ability to resize
  • Loading branch information
jstout211 committed Feb 2, 2023
1 parent e1d3f0a commit 1661de1
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions enigmeg/QA/ImageSelectorGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import copy
import enigmeg
import logging
from PIL import Image, ImageDraw
from PIL import Image, ImageDraw, ImageFont

# =============================================================================
# Defaults
Expand Down Expand Up @@ -137,15 +137,19 @@ def resize_image(image_path, resize=(200,200), status=None,
img = PIL.Image.open(data_bytes_io)
cur_width, cur_height = img.size
status_color = status_color_dict[status]
if resize:
new_width, new_height = resize
scale = min(new_height/cur_height, new_width/cur_width)
img = img.resize((int(cur_width*scale), int(cur_height*scale)))
img_draw = ImageDraw.Draw(img)
#Add text box
img_draw.rectangle((0, 580, 600, 600), outline=None, fill=status_color)
img_draw.text((20, 590), text_val, align='center', fill='black')

new_width, new_height = resize
scale = min(new_height/cur_height, new_width/cur_width)
img = img.resize((int(cur_width*scale), int(cur_height*scale)))
img_draw = ImageDraw.Draw(img)
#Add text box
img_draw.rectangle((0, 580, 600, 600), outline=None, fill=status_color)
try:
font = ImageFont.truetype("DejaVuSans.ttf", size=20)
img_draw.text((20, 580), text_val, font=font, align='center', fill='black')
except:
#Fallback if DejaVuSans not available - but should be installed
#with matplotlib
img_draw.text((20, 580), text_val, align='center', fill='black')
bio = io.BytesIO()
img.save(bio, format="PNG")
return base64.b64encode(bio.getvalue())
Expand Down

0 comments on commit 1661de1

Please sign in to comment.