Compare commits

..

No commits in common. "15645526d50ad54acd3a29a0169efc57d43db527" and "d8683f9fd2514079c4bc15c451df23b46800e22d" have entirely different histories.

1 changed files with 8 additions and 16 deletions

View File

@ -74,7 +74,7 @@ func (p *MemePlugin) registerWeb(c bot.Connector) {
log.Debug().Msgf("image is at %s", u.String()) log.Debug().Msgf("image is at %s", u.String())
p.bot.Send(c, bot.Message, channel, "", bot.ImageAttachment{ p.bot.Send(c, bot.Message, channel, "", bot.ImageAttachment{
URL: u.String(), URL: u.String(),
AltTxt: fmt.Sprintf("%s: %s", user, parts[1]), AltTxt: user,
}) })
w.Write(nil) w.Write(nil)
}) })
@ -87,15 +87,16 @@ func (p *MemePlugin) registerWeb(c bot.Connector) {
}) })
} }
func DownloadTemplate(u *url.URL) image.Image { func DownloadTemplate(file string) image.Image {
res, err := http.Get(u.String()) url := fmt.Sprintf("https://imgflip.com/s/meme/%s", file)
res, err := http.Get(url)
if err != nil { if err != nil {
log.Error().Msgf("template from %s failed because of %v", u.String(), err) log.Error().Msgf("%s template from %s failed because of %v", file, url, err)
} }
defer res.Body.Close() defer res.Body.Close()
image, _, err := image.Decode(res.Body) image, _, err := image.Decode(res.Body)
if err != nil { if err != nil {
log.Error().Msgf("Could not decode %v because of %v", u, err) log.Error().Msgf("Could not decode %s because of %v", file, err)
} }
return image return image
} }
@ -121,16 +122,7 @@ func (p *MemePlugin) genMeme(meme, text string) string {
if !ok { if !ok {
imgName = meme imgName = meme
} }
img := DownloadTemplate(imgName)
u, err := url.Parse(imgName)
if err != nil || u.Scheme == "" {
log.Debug().Err(err).Str("imgName", imgName).Msgf("url not detected")
u, _ = url.Parse("https://imgflip.com/s/meme/" + imgName)
}
log.Debug().Msgf("Attempting to download url: %s", u.String())
img := DownloadTemplate(u)
r := img.Bounds() r := img.Bounds()
w := r.Dx() w := r.Dx()
h := r.Dy() h := r.Dy()
@ -138,7 +130,7 @@ func (p *MemePlugin) genMeme(meme, text string) string {
m := gg.NewContext(w, h) m := gg.NewContext(w, h)
m.DrawImage(img, 0, 0) m.DrawImage(img, 0, 0)
fontLocation := p.c.Get("meme.font", "impact.ttf") fontLocation := p.c.Get("meme.font", "impact.ttf")
err = m.LoadFontFace(fontLocation, fontSize) // problem err := m.LoadFontFace(fontLocation, fontSize) // problem
if err != nil { if err != nil {
log.Error().Err(err).Msg("could not load font") log.Error().Err(err).Msg("could not load font")
} }