mirror of
https://github.com/photoprism/photoprism.git
synced 2026-01-23 02:24:24 +00:00
Thumbnails: Add panic handler for unexpected image encoding errors #3858
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
eae09353f2
commit
d0ea838b37
2 changed files with 18 additions and 0 deletions
|
|
@ -1,8 +1,10 @@
|
|||
package thumb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
|
||||
|
|
@ -12,6 +14,13 @@ import (
|
|||
|
||||
// Jpeg converts an image to JPEG, saves it, and returns it.
|
||||
func Jpeg(srcFile, jpgFile string, orientation int) (img image.Image, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("jpeg: %s (panic)\nstack: %s", r, debug.Stack())
|
||||
log.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Resolve symlinks.
|
||||
if srcFile, err = fs.Resolve(srcFile); err != nil {
|
||||
log.Debugf("jpeg: %s in %s (resolve filename)", err, clean.Log(srcFile))
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package thumb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/png"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
|
||||
|
|
@ -13,6 +15,13 @@ import (
|
|||
|
||||
// Png converts an image to PNG, saves it, and returns it.
|
||||
func Png(srcFile, pngFile string, orientation int) (img image.Image, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("png: %s (panic)\nstack: %s", r, debug.Stack())
|
||||
log.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Resolve symlinks.
|
||||
if srcFile, err = fs.Resolve(srcFile); err != nil {
|
||||
log.Debugf("png: %s in %s (resolve filename)", err, clean.Log(srcFile))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue