fix: show original image if can't thumbnail

See decentral1se/distribusi-go#5
This commit is contained in:
decentral1se 2022-02-04 20:41:19 +01:00
parent 52be2da390
commit c49f164590
No known key found for this signature in database
GPG Key ID: 03789458B3D0C410

View File

@ -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>",