custom font
This commit is contained in:
parent
1dfb6672fa
commit
1a9155f3d8
Binary file not shown.
|
|
@ -56,6 +56,7 @@ def make_wordcloud(WORDS_IN_CHAT):
|
||||||
wordcloud = WordCloud(width = 2000, height = 2000,
|
wordcloud = WordCloud(width = 2000, height = 2000,
|
||||||
background_color = None,
|
background_color = None,
|
||||||
mode="RGBA",
|
mode="RGBA",
|
||||||
|
font_path=f"{RESOURCE_LOCATION}/ArchitectsDaughter.ttf",
|
||||||
prefer_horizontal=1,
|
prefer_horizontal=1,
|
||||||
mask = img_mask,
|
mask = img_mask,
|
||||||
# relative_scaling=1,
|
# relative_scaling=1,
|
||||||
|
|
@ -82,7 +83,8 @@ def make_timeline(participants):
|
||||||
"title": {"text": "Timeline of Messages",
|
"title": {"text": "Timeline of Messages",
|
||||||
"xanchor": "center",
|
"xanchor": "center",
|
||||||
"x": 0.5,
|
"x": 0.5,
|
||||||
"font": {"color": "white"}},
|
"font": {"color": "white",
|
||||||
|
"family": "Architects Daughter"}},
|
||||||
"xaxis": {"showgrid": False,
|
"xaxis": {"showgrid": False,
|
||||||
"title": "",
|
"title": "",
|
||||||
"color": "white"},
|
"color": "white"},
|
||||||
|
|
@ -90,6 +92,7 @@ def make_timeline(participants):
|
||||||
"nticks": 2,
|
"nticks": 2,
|
||||||
"title": "",
|
"title": "",
|
||||||
"color": "white"},
|
"color": "white"},
|
||||||
|
"font": {"family": "Architects Daughter"},
|
||||||
"paper_bgcolor": 'rgba(0,0,0,0)',
|
"paper_bgcolor": 'rgba(0,0,0,0)',
|
||||||
"plot_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:
|
for p in participants:
|
||||||
df_c = pd.DataFrame({"message": [], "counts": [], "sender": []})
|
df_c = pd.DataFrame({"message": [], "counts": [], "sender": []})
|
||||||
df_p = p.words.loc[p.words['message'].isin(list(words.keys()))]
|
df_p = p.words.loc[p.words['message'].isin(list(words.keys()))]
|
||||||
|
df_c.plot()
|
||||||
|
|
||||||
words_count = df_p['message'].value_counts().sort_index()
|
words_count = df_p['message'].value_counts().sort_index()
|
||||||
df_c = words_count.rename_axis('message').reset_index(name='counts')
|
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,
|
"bargap": 0.5,
|
||||||
"title": {"text": "MOST USED WORDS",
|
"title": {"text": "MOST USED WORDS",
|
||||||
"x": 0.5,
|
"x": 0.5,
|
||||||
"font": {"color": "white"}},
|
"font": {"color": "white",
|
||||||
|
"family": "Architects Daughter"}},
|
||||||
"xaxis": {"showgrid": False,
|
"xaxis": {"showgrid": False,
|
||||||
"title": "",
|
"title": "",
|
||||||
"nticks": 5,
|
"nticks": 5,
|
||||||
|
|
@ -135,6 +140,7 @@ def make_barchart(participants, WORDS_IN_CHAT):
|
||||||
"categoryorder": "sum ascending",
|
"categoryorder": "sum ascending",
|
||||||
"title": {"text": ""},
|
"title": {"text": ""},
|
||||||
"color": "white"},
|
"color": "white"},
|
||||||
|
"font": {"family": "Architects Daughter"},
|
||||||
"paper_bgcolor": 'rgba(255,255,255,0)',
|
"paper_bgcolor": 'rgba(255,255,255,0)',
|
||||||
"plot_bgcolor": 'rgba(255,255,255,0)'
|
"plot_bgcolor": 'rgba(255,255,255,0)'
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -7,20 +7,21 @@ RESOURCE_LOCATION = f"{path.abspath('Resources')}"
|
||||||
|
|
||||||
def generate_images_from_text(x, y, txt):
|
def generate_images_from_text(x, y, txt):
|
||||||
fontsize = 1 # starting font size
|
fontsize = 1 # starting font size
|
||||||
|
font =f"{RESOURCE_LOCATION}/ArchitectsDaughter.ttf"
|
||||||
img = Image.new('RGBA', (x, y), (0, 0, 0, 0))
|
img = Image.new('RGBA', (x, y), (0, 0, 0, 0))
|
||||||
|
|
||||||
# portion of image width you want text width to be
|
# portion of image width you want text width to be
|
||||||
img_fraction = 0.80
|
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]:
|
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
|
# iterate until the text size is just larger than the criteria
|
||||||
fontsize += 1
|
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
|
# optionally de-increment to be sure it is less than criteria
|
||||||
fontsize -= 1
|
fontsize -= 1
|
||||||
fnt = ImageFont.truetype("/home/koma52/.fonts/Ubuntu.ttf", fontsize)
|
fnt = ImageFont.truetype(font, fontsize)
|
||||||
|
|
||||||
d = ImageDraw.Draw(img)
|
d = ImageDraw.Draw(img)
|
||||||
d.text((x/2,y/2), str(txt), font=fnt, fill=(255,255,255), anchor="mm")
|
d.text((x/2,y/2), str(txt), font=fnt, fill=(255,255,255), anchor="mm")
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,5 @@ pandas
|
||||||
wordcloud
|
wordcloud
|
||||||
numpy
|
numpy
|
||||||
plotly
|
plotly
|
||||||
kaleido
|
kaleido
|
||||||
|
emoji
|
||||||
Loading…
Reference in New Issue