custom font

This commit is contained in:
Kónya Márton 2022-11-28 23:11:09 +01:00
parent 1dfb6672fa
commit 1a9155f3d8
4 changed files with 14 additions and 6 deletions

Binary file not shown.

View File

@ -56,6 +56,7 @@ def make_wordcloud(WORDS_IN_CHAT):
wordcloud = WordCloud(width = 2000, height = 2000,
background_color = None,
mode="RGBA",
font_path=f"{RESOURCE_LOCATION}/ArchitectsDaughter.ttf",
prefer_horizontal=1,
mask = img_mask,
# relative_scaling=1,
@ -82,7 +83,8 @@ def make_timeline(participants):
"title": {"text": "Timeline of Messages",
"xanchor": "center",
"x": 0.5,
"font": {"color": "white"}},
"font": {"color": "white",
"family": "Architects Daughter"}},
"xaxis": {"showgrid": False,
"title": "",
"color": "white"},
@ -90,6 +92,7 @@ def make_timeline(participants):
"nticks": 2,
"title": "",
"color": "white"},
"font": {"family": "Architects Daughter"},
"paper_bgcolor": 'rgba(0,0,0,0)',
"plot_bgcolor": 'rgba(0,0,0,0)'
})
@ -108,6 +111,7 @@ def make_barchart(participants, WORDS_IN_CHAT):
for p in participants:
df_c = pd.DataFrame({"message": [], "counts": [], "sender": []})
df_p = p.words.loc[p.words['message'].isin(list(words.keys()))]
df_c.plot()
words_count = df_p['message'].value_counts().sort_index()
df_c = words_count.rename_axis('message').reset_index(name='counts')
@ -125,7 +129,8 @@ def make_barchart(participants, WORDS_IN_CHAT):
"bargap": 0.5,
"title": {"text": "MOST USED WORDS",
"x": 0.5,
"font": {"color": "white"}},
"font": {"color": "white",
"family": "Architects Daughter"}},
"xaxis": {"showgrid": False,
"title": "",
"nticks": 5,
@ -135,6 +140,7 @@ def make_barchart(participants, WORDS_IN_CHAT):
"categoryorder": "sum ascending",
"title": {"text": ""},
"color": "white"},
"font": {"family": "Architects Daughter"},
"paper_bgcolor": 'rgba(255,255,255,0)',
"plot_bgcolor": 'rgba(255,255,255,0)'
})

View File

@ -7,20 +7,21 @@ RESOURCE_LOCATION = f"{path.abspath('Resources')}"
def generate_images_from_text(x, y, txt):
fontsize = 1 # starting font size
font =f"{RESOURCE_LOCATION}/ArchitectsDaughter.ttf"
img = Image.new('RGBA', (x, y), (0, 0, 0, 0))
# portion of image width you want text width to be
img_fraction = 0.80
fnt = ImageFont.truetype('/home/koma52/.fonts/Ubuntu.ttf', fontsize)
fnt = ImageFont.truetype(font, fontsize)
while fnt.getbbox(str(txt))[2] - fnt.getbbox(str(txt))[0] < img_fraction*img.size[0]:
# iterate until the text size is just larger than the criteria
fontsize += 1
fnt = ImageFont.truetype("/home/koma52/.fonts/Ubuntu.ttf", fontsize)
fnt = ImageFont.truetype(font, fontsize)
# optionally de-increment to be sure it is less than criteria
fontsize -= 1
fnt = ImageFont.truetype("/home/koma52/.fonts/Ubuntu.ttf", fontsize)
fnt = ImageFont.truetype(font, fontsize)
d = ImageDraw.Draw(img)
d.text((x/2,y/2), str(txt), font=fnt, fill=(255,255,255), anchor="mm")

View File

@ -4,4 +4,5 @@ pandas
wordcloud
numpy
plotly
kaleido
kaleido
emoji