Skip to content

Commit

Permalink
put short words on one line
Browse files Browse the repository at this point in the history
  • Loading branch information
Lewis Tian committed Jul 28, 2019
1 parent 28ccc3e commit edcbca4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Binary file removed cat-calendar/src/images/default_cat.png
Binary file not shown.
8 changes: 5 additions & 3 deletions cat-calendar/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@ def render_image(self):
except:
text = '只要你坚持不懈的,去追你喜欢的人,总有一天你会被他拉黑。'

table = {ord(f): ord(t) for f, t in zip(u',。', u',.')}
text = text.translate(table).replace(',', '\n').replace('.', '')
date_w, date_h2 = ImageDraw.Draw(Image.new(mode='RGB', size=(1, 1))).textsize(text, font=normal_font)

if date_w > 930:
table = {ord(f): ord(t) for f, t in zip(u',。', u',.')}
text = text.translate(table).replace(',', '\n').replace('.', '')
date_w, date_h2 = ImageDraw.Draw(Image.new(mode='RGB', size=(1, 1))).textsize(text, font=normal_font)
# one/dutang text
y += inner_padding+shift*2
y += inner_padding+shift*3
draw.text((outter_padding+inner_padding*2, y), text, font=normal_font, fill=text_color[1], spacing=line_space)

y += date_h2+len(text.split('\n'))*line_space
Expand Down

0 comments on commit edcbca4

Please sign in to comment.