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"
|
2020-07-18 16:54:13 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
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 {
|
2020-07-18 16:54:13 +02:00
|
|
|
log.Errorf("resample: can't open %s", txt.Quote(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 {
|
2020-07-18 16:54:13 +02:00
|
|
|
log.Errorf("resample: failed to save %s", txt.Quote(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
|
|
|
}
|