Browse Source

fix: show original image if can't thumbnail

See https://git.vvvvvvaria.org/decentral1se/distribusi-go/issues/5
main
decentral1se 3 years ago
parent
commit
c49f164590
No known key found for this signature in database GPG Key ID: 3789458B3D0C410
  1. 10
      distribusi.go

10
distribusi.go

@ -453,14 +453,8 @@ func getMtype(fpath string) (string, error) {
// genThumb generates an in-memory image thumbnail and encodes it into a base64
// representation which is suitable for embedding in HTML pages.
func genThumb(c *cli.Context, fpath, caption string) (string, error) {
knownFailureExts := []string{".ico", ".svg", ".xcf"}
if sliceContains(knownFailureExts, filepath.Ext(fpath)) {
return "", fmt.Errorf("unable to generate thumbnail for %s", fpath)
}
imgSrc, err := imaging.Open(fpath, imaging.AutoOrientation(true))
if err != nil {
logrus.Debugf("failed to generate thumbnail for %s", fpath)
return "", err
}
@ -577,8 +571,8 @@ func getHref(c *cli.Context, fpath string, mtype string) (bool, string, error) {
} else {
thumb, err := genThumb(c, fpath, caption)
if err != nil {
unknown = true
href = fmt.Sprintf("<a class='%s' href=\"%s\">%s</a>", stype, fname, fname)
logrus.Debugf("failed to generate thumbnail for %s, showing original image", fpath)
href = fmt.Sprintf("<img class='%s' src=\"%s\" />", stype, fname)
} else {
href = fmt.Sprintf(
"<figure><a href=\"%s\"><img class='thumbnail' loading='lazy' src='data:image/jpg;base64,%s'></a><figcaption>%s</figcaption></figure>",

Loading…
Cancel
Save