mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-04-25 04:46:24 +02:00
parent
0791f8ceec
commit
969ce986d2
3 changed files with 10 additions and 5 deletions
|
|
@ -27,6 +27,7 @@ import (
|
|||
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/muesli/smartcrop"
|
||||
"github.com/muesli/smartcrop/nfnt"
|
||||
"github.com/rwcarlsen/goexif/exif"
|
||||
"golang.org/x/image/tiff" // register tiff format
|
||||
_ "golang.org/x/image/webp" // register webp format
|
||||
|
|
@ -156,6 +157,8 @@ func resizeParams(m image.Image, opt Options) (w, h int, resize bool) {
|
|||
return w, h, true
|
||||
}
|
||||
|
||||
var smartcropAnalyzer = smartcrop.NewAnalyzer(nfnt.NewDefaultResizer())
|
||||
|
||||
// cropParams calculates crop rectangle parameters to keep it in image bounds
|
||||
func cropParams(m image.Image, opt Options) image.Rectangle {
|
||||
if !opt.SmartCrop && opt.CropX == 0 && opt.CropY == 0 && opt.CropWidth == 0 && opt.CropHeight == 0 {
|
||||
|
|
@ -169,12 +172,10 @@ func cropParams(m image.Image, opt Options) image.Rectangle {
|
|||
if opt.SmartCrop {
|
||||
w := evaluateFloat(opt.Width, imgW)
|
||||
h := evaluateFloat(opt.Height, imgH)
|
||||
log.Printf("smartcrop input: %dx%d", w, h)
|
||||
r, err := smartcrop.SmartCrop(m, w, h)
|
||||
r, err := smartcropAnalyzer.FindBestCrop(m, w, h)
|
||||
if err != nil {
|
||||
log.Printf("error with smartcrop: %v", err)
|
||||
log.Printf("smartcrop error finding best crop: %v", err)
|
||||
} else {
|
||||
log.Printf("smartcrop rectangle: %v", r)
|
||||
return r
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue