2020-01-06 17:50:05 +01:00
|
|
|
package thumb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
|
|
|
|
"github.com/disintegration/imaging"
|
|
|
|
)
|
|
|
|
|
2020-05-01 11:53:41 +02:00
|
|
|
func Jpeg(srcFilename, jpgFilename string) (img image.Image, err error) {
|
|
|
|
img, err = imaging.Open(srcFilename, imaging.AutoOrientation(true))
|
2020-01-06 17:50:05 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2020-05-03 18:05:05 +02:00
|
|
|
log.Errorf("resample: can't open %s", srcFilename)
|
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
|
|
|
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-05-03 18:05:05 +02:00
|
|
|
log.Errorf("resample: failed to save %s", 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
|
|
|
}
|