Merge pull request #332 from velour/memecaps

meme: add capitalization to configs, true default
This commit is contained in:
Chris Sexton 2021-01-09 15:30:12 -05:00 committed by GitHub
commit c61b84d21b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -42,6 +42,7 @@ type memeText struct {
XPerc float64 `json:"x"` XPerc float64 `json:"x"`
YPerc float64 `json:"y"` YPerc float64 `json:"y"`
Text string `json:"t"` Text string `json:"t"`
Caps bool `json:"c"`
} }
var horizon = 24 * 7 var horizon = 24 * 7
@ -329,8 +330,8 @@ func (p *MemePlugin) findFontSize(config []memeText, w, h int, sizes []float64)
func defaultFormatConfig() []memeText { func defaultFormatConfig() []memeText {
return []memeText{ return []memeText{
{XPerc: 0.5, YPerc: 0.05}, {XPerc: 0.5, YPerc: 0.05, Caps: true},
{XPerc: 0.5, YPerc: 0.95}, {XPerc: 0.5, YPerc: 0.95, Caps: true},
} }
} }
@ -395,6 +396,12 @@ func (p *MemePlugin) genMeme(meme string, bully image.Image, config []memeText)
fontLocation := p.c.Get("meme.font", "impact.ttf") fontLocation := p.c.Get("meme.font", "impact.ttf")
m.LoadFontFace(fontLocation, p.findFontSize(config, w, h, fontSizes)) m.LoadFontFace(fontLocation, p.findFontSize(config, w, h, fontSizes))
for i, c := range config {
if c.Caps {
config[i].Text = strings.ToUpper(c.Text)
}
}
// Apply black stroke // Apply black stroke
m.SetHexColor("#000") m.SetHexColor("#000")
strokeSize := 6 strokeSize := 6

View File

@ -46,7 +46,7 @@ func (p *MemePlugin) all(w http.ResponseWriter, r *http.Request) {
for n, u := range memes { for n, u := range memes {
config, ok := configs[n] config, ok := configs[n]
if !ok { if !ok {
b, _ := json.Marshal(defaultFormatConfig) b, _ := json.Marshal(defaultFormatConfig())
config = string(b) config = string(b)
} }
realURL, err := url.Parse(u) realURL, err := url.Parse(u)