You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make sure you have a working Go environment (Go 1.12 or higher is required).
See the install instructions.
To install smartcrop, simply run:
go get github.com/muesli/smartcrop
To compile it from source:
git clone https://github.com/muesli/smartcrop.git
cd smartcrop
go build
Example
package main
import (
"fmt""image"
_ "image/png""os""github.com/muesli/smartcrop""github.com/muesli/smartcrop/nfnt"
)
funcmain() {
f, _:=os.Open("image.png")
img, _, _:=image.Decode(f)
analyzer:=smartcrop.NewAnalyzer(nfnt.NewDefaultResizer())
topCrop, _:=analyzer.FindBestCrop(img, 250, 250)
// The crop will have the requested aspect ratio, but you need to copy/scale it yourselffmt.Printf("Top crop: %+v\n", topCrop)
typeSubImagerinterface {
SubImage(r image.Rectangle) image.Image
}
croppedimg:=img.(SubImager).SubImage(topCrop)
// ...
}
Also see the test cases in smartcrop_test.go and cli application in cmd/smartcrop/ for further working examples.
Simple CLI application
go install github.com/muesli/smartcrop/cmd/smartcrop
Usage of smartcrop:
-height int
crop height
-input string
input filename
-output string
output filename
-quality int
jpeg quality (default 85)
-resize
resize after cropping (default true)
-width int
crop width