Skip to content

Commit

Permalink
Fix signature misalignment
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxJohansen committed Jul 4, 2018
1 parent 35d8e9a commit 23d86b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions diploma.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def draw_centered_full_size(context, size, field):
font size that won't overflow its bounding box."""
text = field.value
rect = get_rect(field, size)
font = get_font_that_fits_in_box(text, rect[:2])
font = get_font_that_fits_in_box(text, rect)
center = center_text_in_rect(font.getsize(text), rect)
context.text(center, field.value, font=font, fill=ImageColor.getrgb(field.color))

Expand All @@ -79,12 +79,13 @@ def draw_scaled_signature(image, signature):
"""Draws the signature field onto the image.
The signature will be scaled to fit into its area
while preserving its aspect ratio."""
rect = get_rect(signature, image.size)
x1, y1, x2, y2 = get_rect(signature, image.size)
size = x2 - x1, y2 - y1
signature = Image \
.open(signature.value) \
.convert('RGBA')
signature.thumbnail(rect[:2])
image.paste(signature, box=rect[:2])
signature.thumbnail(size)
image.paste(signature, box=(x1, y1))


def create_diploma_image(template):
Expand Down
2 changes: 1 addition & 1 deletion template.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def create_clean_template(template_dict):
cleaned.pop('path', None)
signature = cleaned.pop('signature', False)
field_dicts = cleaned['fields']
cleaned['fields'] = list(field_dicts.keys())
cleaned['fields'] = [{'name': k} for k in field_dicts]
cleaned['signature'] = bool(signature)
return cleaned

Expand Down

0 comments on commit 23d86b0

Please sign in to comment.