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