Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taschenlogo #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions wordcloud/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
all: build/wordcloud.png
all: build/logo_tasche_negativ_schwarz_weiss.png


build/wordcloud.png: ../logos/build/schwingung_positiv.png
build/wordcloud.png: specific_pep_words.txt words_of_physics.txt | build
build/wordcloud.png: ../logos/build/schwingung_positiv.png
build/wordcloud_negativ.png: specific_pep_words.txt words_of_physics.txt schwingung_negativ_high_res.png| build
python pep_wordcloud.py

../logos/build/schwingung_positiv.png:
make -C ../logos build/schwingung_positiv.png

build/logo_tasche_negativ_schwarz_weiss.png: build/wordcloud_negativ.png | build
python pep_taschen.py


build:
mkdir -p build

Expand Down
81 changes: 81 additions & 0 deletions wordcloud/pep_taschen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import image, font_manager
import os


WIDTH = 4000 # 1920
HEIGHT = WIDTH*1.1 # 1920


def px2inch(pixel, ppi=96):
'''
Transform a number of pixel to the size in inch

param pixel: The number of pixels
param ppi: The pixel per inch resolution
return: The size in inches
'''
return pixel / ppi


# Use Akkurat font
font_path = os.path.expanduser('~/.fonts/AkkBd_Office.otf')
pepfont=font_manager.FontProperties(fname=font_path)

# Import the wordcloud and logos
logo_neg = image.imread('schwingung_negativ_high_res.png')
# logo_neg_grey = image.imread('schwingung_negativ_grey.png')
wordcloud_pos = image.imread(os.path.join('build', 'pep_wordcloud_positiv.png'))
wordcloud_neg = image.imread(os.path.join('build', 'pep_wordcloud_negativ.png'))


def two_color_logo(width, height, pep_logo, pep_wordcloud, color_address, filepath):
'''
Create a pep logo with the wordcloud and the web address

param width: Figure width in pixel
param height: Figure height in pixel
param pep_logo: Numpy array of the pep_logo image (see matplotlib.image)
param pep_wordcloud: Numpy array of the wordcloud image (see matplotlib.image)
param color_address: Color of the web address
param filename: Path to save the image
'''
plt.figure(figsize = (px2inch(width), px2inch(height)), facecolor = None)
plt.imshow(pep_logo)
plt.imshow(pep_wordcloud)
axes = plt.gca()
upper, lower = axes.get_ylim() # Logo size
plt.text(0.5*upper, upper*1.1,
'www.pep-dortmund.org',
fontproperties=pepfont,
verticalalignment='bottom',
horizontalalignment='center',
size=WIDTH/25,
color=color_address)
plt.ylim([upper*1.11, lower])
plt.xlim([lower, upper])
plt.axis("off")
plt.tight_layout(pad=0, h_pad=0, w_pad=0)
plt.savefig(filepath, transparent=True)
plt.clf()

# PeP bag logo in black and white
two_color_logo(
width=WIDTH,
height=HEIGHT,
pep_logo=logo_neg,
pep_wordcloud=wordcloud_pos,
color_address='black',
filepath=os.path.join('build', 'logo_tasche_negativ_schwarz_weiss.png'),
)

# PeP bag logo in grey and white
# two_color_logo(
# width=WIDTH,
# height=HEIGHT,
# pep_logo=logo_neg_grey,
# pep_wordcloud=wordcloud_pos,
# color_address=(86/255, 86/255, 86/255, 1),
# filepath=os.path.join('build', 'logo_tasche_negativ_grau_weiss.png'),
# )
13 changes: 10 additions & 3 deletions wordcloud/pep_wordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ def higlight_pep(word, **kwargs):
mask = (alphaimg == 0.0) | (rimg == 1)
mask = 255 * mask.astype(int)

# WordCloud requires Akkurat Font - Check PeP Nextcloud

# Link to documentation
# https://amueller.github.io/word_cloud/generated/wordcloud.WordCloud.html
wc = WordCloud(
font_path = 'AkkBd_Office.otf',
font_path = os.path.expanduser('~/.fonts/AkkBd_Office.otf'),
background_color = "rgba(255, 255, 255, 0)",
mode = "RGBA",
random_state = 42,
Expand All @@ -98,13 +100,18 @@ def higlight_pep(word, **kwargs):
color_func = lambda *args,
**kwargs: 'rgb(255, 255, 255)'
)

word_cloud = wc.generate(words)

# Save positive wordcloud as png
save_path = os.path.join('build/pep_wordcloud_positiv.png')
word_cloud.to_file(save_path)

# Invert wordcloud for black text
word_cloud.recolor(
random_state=42,
color_func=lambda *args,
**kwargs : 'rgb(0, 0, 0)')

save_path = os.path.join('build/pep_wordcloud.png')
# Save negative wordcloud as png
save_path = os.path.join('build/pep_wordcloud_negativ.png')
word_cloud.to_file(save_path)
Binary file added wordcloud/schwingung_negativ_high_res.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading