Skip to content

Commit

Permalink
Code for social card
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed Aug 14, 2024
1 parent 8599fb6 commit f285052
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ flamegraph.svg
perf.data*
*.csv
*.pdf
*.png
54 changes: 54 additions & 0 deletions extra/card.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from PIL import Image
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm

# start plot
(fig, ax) = plt.subplots(figsize=(10, 5))
plt.xticks([])
plt.yticks([])
for side in ["bottom", "top", "left", "right"]:
ax.spines[side].set_color("#FFFFFF00")

# colors
col_dark = "#191924"
col_yellow = "#eed858"
col_light = "#faf7e5"

outer_col = col_yellow
inner_col = col_light
text_col = col_dark

# outer box
w = 200
h = 100
xs_outer = [w/2, w, w, 0, 0, w/2]
ys_outer = [0, 0, h, h, 0, 0]
plt.fill(xs_outer, ys_outer, c=outer_col, lw=1, zorder=1)

# inner box
dw = 23
dh = 20
xs_inner = [w/2, w-dw, w-dw, dw, dw, w/2]
ys_inner = [dh, dh, h-dh, h-dh, dh, dh]
plt.plot(xs_inner, ys_inner, c=inner_col, lw=30, zorder=2)
plt.fill(xs_inner, ys_inner, c=inner_col, lw=0)

# logo
img = Image.open("logo.png").resize((900, 900))
fig.figimage(img, 2210, 540)

# text
fontfamily = "Roboto Slab"
fonts = fm.findSystemFonts(fontpaths=None, fontext='ttf')
[fm.fontManager.addfont(f) for f in fonts if fontfamily.split()[0] in f]

fontsize = 16
plt.text(31, 50, "An extremely fast La\nformatter written in Rust.", fontsize=fontsize, ha="left", va="center", fontweight="light", c=text_col, fontfamily=fontfamily, fontstyle="normal")

plt.text(92.6, 53.53, "T", fontsize=fontsize, ha="left", va="center", fontweight="light", c=text_col, fontfamily=fontfamily, fontstyle="normal")

plt.text(96.55, 53.53, "eX", fontsize=fontsize, ha="left", va="center", fontweight="light", c=text_col, fontfamily=fontfamily, fontstyle="normal")

# save
plt.savefig("card.svg", dpi=400, transparent=True)
plt.close("all")
14 changes: 4 additions & 10 deletions extra/logo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
fonts = fm.findSystemFonts(fontpaths=None, fontext='ttf')

# start plot
(fig, ax) = plt.subplots(figsize=(5, 5))
Expand Down Expand Up @@ -41,19 +40,14 @@

# text
fontfamily = "Bungee"
fonts = [f for f in fonts if fontfamily.split()[0] in f]
for font in fonts:
fm.fontManager.addfont(font)

fontweight = "light"
fontstyle = "normal"
case = "lower"
fonts = fm.findSystemFonts(fontpaths=None, fontext='ttf')
[fm.fontManager.addfont(f) for f in fonts if fontfamily.split()[0] in f]

fontsize = 100
plt.text(0.5, 0.72, "TEX", fontsize=fontsize, ha="center", va="center", fontweight=fontweight, c=text_col, fontfamily=fontfamily, fontstyle=fontstyle)
plt.text(0.5, 0.72, "TEX", fontsize=fontsize, ha="center", va="center", fontweight="light", c=text_col, fontfamily=fontfamily, fontstyle="normal")

fontsize = 96
plt.text(0.496, 0.25, "FMT", fontsize=fontsize, ha="center", va="center", fontweight=fontweight, c=text_col, fontfamily=fontfamily, fontstyle=fontstyle)
plt.text(0.496, 0.25, "FMT", fontsize=fontsize, ha="center", va="center", fontweight="light", c=text_col, fontfamily=fontfamily, fontstyle="normal")

# save
plt.savefig("logo.svg", dpi=1000, transparent=True)
Expand Down
7 changes: 6 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
default: test clippy format shellcheck

all: default prof perf latex
all: default prof perf latex logo

alias t := test
alias l := latex
Expand Down Expand Up @@ -30,3 +30,8 @@ shellcheck:

logo:
@cd extra && python logo.py
@cd extra && magick -background none logo.svg -resize 5000x5000 logo.png
@cd extra && python card.py
@cd extra && magick -background none card.svg -resize 1280x640\! card.png
@cd extra && inkscape -w 2560 -h 1280 card.svg -o card.png
@cd extra && rm -f logo.png card.svg
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pkgs.mkShell {
python = pkgs.python3.withPackages (ps:
with ps; [
matplotlib
pillow
]);
in [
pkgs.cacert
Expand Down

0 comments on commit f285052

Please sign in to comment.