mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
parent
0791f8ceec
commit
969ce986d2
3 changed files with 10 additions and 5 deletions
2
go.mod
2
go.mod
|
@ -22,7 +22,7 @@ require (
|
|||
github.com/jtolds/gls v4.2.1+incompatible // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/marstr/guid v0.0.0-20170427235115-8bdf7d1a087c // indirect
|
||||
github.com/muesli/smartcrop v0.0.0-20171215203440-9032446b30f6
|
||||
github.com/muesli/smartcrop v0.2.1-0.20181030220600-548bbf0c0965
|
||||
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 // indirect
|
||||
github.com/peterbourgon/diskv v0.0.0-20171120014656-2973218375c3
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -49,6 +49,10 @@ github.com/marstr/guid v0.0.0-20170427235115-8bdf7d1a087c h1:N7uWGS2fTwH/4BwxbHi
|
|||
github.com/marstr/guid v0.0.0-20170427235115-8bdf7d1a087c/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho=
|
||||
github.com/muesli/smartcrop v0.0.0-20171215203440-9032446b30f6 h1:m5kCp2hHRMu7z95f+aIK80l8N1tx+UXAqNoYpRS9v3o=
|
||||
github.com/muesli/smartcrop v0.0.0-20171215203440-9032446b30f6/go.mod h1:i2fCI/UorTfgEpPPLWiFBv4pye+YAG78RwcQLUkocpI=
|
||||
github.com/muesli/smartcrop v0.2.0 h1:HV/xtsW5sc5xuZY39sxJXtTBwoF8RUJzQNhwwZhyGjE=
|
||||
github.com/muesli/smartcrop v0.2.0/go.mod h1:i2fCI/UorTfgEpPPLWiFBv4pye+YAG78RwcQLUkocpI=
|
||||
github.com/muesli/smartcrop v0.2.1-0.20181030220600-548bbf0c0965 h1:BdOnvj+P+06ZFwYd07iFWXHPfRyrJd5sAXpX9+E8bxM=
|
||||
github.com/muesli/smartcrop v0.2.1-0.20181030220600-548bbf0c0965/go.mod h1:i2fCI/UorTfgEpPPLWiFBv4pye+YAG78RwcQLUkocpI=
|
||||
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY=
|
||||
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/peterbourgon/diskv v0.0.0-20171120014656-2973218375c3 h1:ZKRE3mqKoxObHs5oWjLnA1WxXhmlDDAVuE0VsuLIoNk=
|
||||
|
|
|
@ -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…
Reference in a new issue