From 295d9fef77a920d9e91b0e3d6dcf224d57e562d5 Mon Sep 17 00:00:00 2001 From: Chris Sexton <3216719+chrissexton@users.noreply.github.com> Date: Thu, 16 Mar 2023 13:30:49 -0400 Subject: [PATCH] tap: maybe fix font locations --- plugins/meme/meme.go | 10 +++++----- plugins/tappd/image.go | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/meme/meme.go b/plugins/meme/meme.go index 178c385..319eabf 100644 --- a/plugins/meme/meme.go +++ b/plugins/meme/meme.go @@ -329,7 +329,7 @@ func FindFontSize(c *config.Config, config []string, fontLocation string, w, h i longestStr, longestW := "", 0.0 for _, s := range config { - err := m.LoadFontFace(getFont(c, fontLocation), 12) + err := m.LoadFontFace(GetFont(c, fontLocation), 12) if err != nil { log.Error().Err(err).Msg("could not load font") return fontSize @@ -343,7 +343,7 @@ func FindFontSize(c *config.Config, config []string, fontLocation string, w, h i } for _, sz := range sizes { - err := m.LoadFontFace(getFont(c, fontLocation), sz) // problem + err := m.LoadFontFace(GetFont(c, fontLocation), sz) // problem if err != nil { log.Error().Err(err).Msg("could not load font") return fontSize @@ -476,7 +476,7 @@ func (p *MemePlugin) genMeme(spec specification) ([]byte, error) { if fontLocation == "" { fontLocation = defaultFont } - m.LoadFontFace(getFont(p.c, fontLocation), fontSize) + m.LoadFontFace(GetFont(p.c, fontLocation), fontSize) x := float64(w)*c.XPerc + float64(dx) y := float64(h)*c.YPerc + float64(dy) m.DrawStringAnchored(c.Text, x, y, 0.5, 0.5) @@ -491,7 +491,7 @@ func (p *MemePlugin) genMeme(spec specification) ([]byte, error) { if fontLocation == "" { fontLocation = defaultFont } - m.LoadFontFace(getFont(p.c, fontLocation), fontSize) + m.LoadFontFace(GetFont(p.c, fontLocation), fontSize) x := float64(w) * c.XPerc y := float64(h) * c.YPerc m.DrawStringAnchored(c.Text, x, y, 0.5, 0.5) @@ -506,7 +506,7 @@ func (p *MemePlugin) genMeme(spec specification) ([]byte, error) { return p.images[jsonSpec].repr, nil } -func getFont(c *config.Config, name string) string { +func GetFont(c *config.Config, name string) string { location := c.Get("meme.fontLocation", "") fontShortcuts := c.GetMap("meme.fontShortcuts", map[string]string{"impact": "impact.ttf"}) if file, ok := fontShortcuts[name]; ok { diff --git a/plugins/tappd/image.go b/plugins/tappd/image.go index 87b1eb1..cfc204d 100644 --- a/plugins/tappd/image.go +++ b/plugins/tappd/image.go @@ -67,7 +67,7 @@ func defaultSpec() textSpec { } func (p *Tappd) overlay(img image.Image, texts []textSpec) ([]byte, error) { - font := p.c.Get("meme.font", "impact.ttf") + font := meme.GetFont(p.c, p.c.Get("meme.font", "impact.ttf")) fontSizes := []float64{48, 36, 24, 16, 12} r := img.Bounds() w := r.Dx() @@ -79,6 +79,7 @@ func (p *Tappd) overlay(img image.Image, texts []textSpec) ([]byte, error) { } fontSize := meme.FindFontSize(p.c, txts, font, w, h, fontSizes) + log.Debug().Msgf("Decided on font size: %d", fontSize) m := gg.NewContext(w, h) m.DrawImage(img, 0, 0)