2020-01-06 17:50:05 +01:00
|
|
|
package thumb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
2020-07-18 16:54:13 +02:00
|
|
|
"path/filepath"
|
2020-01-06 17:50:05 +01:00
|
|
|
|
|
|
|
"github.com/disintegration/imaging"
|
2021-12-14 20:01:39 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/sanitize"
|
2020-01-06 17:50:05 +01:00
|
|
|
)
|
|
|
|
|
2021-02-22 21:09:50 +01:00
|
|
|
func Jpeg(srcFilename, jpgFilename string, orientation int) (img image.Image, err error) {
|
|
|
|
img, err = imaging.Open(srcFilename)
|
2020-01-06 17:50:05 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2022-01-05 11:40:44 +01:00
|
|
|
log.Errorf("resample: cannot open %s", sanitize.Log(filepath.Base(srcFilename)))
|
2020-05-01 11:53:41 +02:00
|
|
|
return img, err
|
2020-01-06 17:50:05 +01:00
|
|
|
}
|
|
|
|
|
2021-02-22 21:09:50 +01:00
|
|
|
if orientation > 1 {
|
|
|
|
img = Rotate(img, orientation)
|
|
|
|
}
|
|
|
|
|
2020-05-01 11:53:41 +02:00
|
|
|
saveOption := imaging.JPEGQuality(JpegQuality)
|
2020-01-06 17:50:05 +01:00
|
|
|
|
2020-05-01 11:53:41 +02:00
|
|
|
if err = imaging.Save(img, jpgFilename, saveOption); err != nil {
|
2021-12-14 20:01:39 +01:00
|
|
|
log.Errorf("resample: failed to save %s", sanitize.Log(filepath.Base(jpgFilename)))
|
2020-05-01 11:53:41 +02:00
|
|
|
return img, err
|
2020-01-06 17:50:05 +01:00
|
|
|
}
|
|
|
|
|
2020-05-01 11:53:41 +02:00
|
|
|
return img, nil
|
2020-01-06 17:50:05 +01:00
|
|
|
}
|