mirror of https://github.com/velour/catbase.git
Compare commits
No commits in common. "15645526d50ad54acd3a29a0169efc57d43db527" and "d8683f9fd2514079c4bc15c451df23b46800e22d" have entirely different histories.
15645526d5
...
d8683f9fd2
|
@ -74,7 +74,7 @@ func (p *MemePlugin) registerWeb(c bot.Connector) {
|
|||
log.Debug().Msgf("image is at %s", u.String())
|
||||
p.bot.Send(c, bot.Message, channel, "", bot.ImageAttachment{
|
||||
URL: u.String(),
|
||||
AltTxt: fmt.Sprintf("%s: %s", user, parts[1]),
|
||||
AltTxt: user,
|
||||
})
|
||||
w.Write(nil)
|
||||
})
|
||||
|
@ -87,15 +87,16 @@ func (p *MemePlugin) registerWeb(c bot.Connector) {
|
|||
})
|
||||
}
|
||||
|
||||
func DownloadTemplate(u *url.URL) image.Image {
|
||||
res, err := http.Get(u.String())
|
||||
func DownloadTemplate(file string) image.Image {
|
||||
url := fmt.Sprintf("https://imgflip.com/s/meme/%s", file)
|
||||
res, err := http.Get(url)
|
||||
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()
|
||||
image, _, err := image.Decode(res.Body)
|
||||
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
|
||||
}
|
||||
|
@ -121,16 +122,7 @@ func (p *MemePlugin) genMeme(meme, text string) string {
|
|||
if !ok {
|
||||
imgName = meme
|
||||
}
|
||||
|
||||
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)
|
||||
img := DownloadTemplate(imgName)
|
||||
r := img.Bounds()
|
||||
w := r.Dx()
|
||||
h := r.Dy()
|
||||
|
@ -138,7 +130,7 @@ func (p *MemePlugin) genMeme(meme, text string) string {
|
|||
m := gg.NewContext(w, h)
|
||||
m.DrawImage(img, 0, 0)
|
||||
fontLocation := p.c.Get("meme.font", "impact.ttf")
|
||||
err = m.LoadFontFace(fontLocation, fontSize) // problem
|
||||
err := m.LoadFontFace(fontLocation, fontSize) // problem
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not load font")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue