smartcrop finds good crops for arbitrary images and crop sizes, based on Jonas Wagner's smartcrop.js
Image: https://www.flickr.com/photos/usfwspacific/8182486789 CC BY U.S. Fish & Wildlife
Image: https://www.flickr.com/photos/endogamia/5682480447 by N. Feans
Make sure you have a working Go environment. See the install instructions.
To install smartcrop, simply run:
go get github.com/muesli/smartcrop
To compile it from source:
cd $GOPATH/src/github.com/muesli/smartcrop
go get -u -v
go build && go test -v
package main
import (
"fmt"
"image"
_ "image/png"
"os"
"github.com/muesli/smartcrop"
)
func main() {
f, _ := os.Open("image.png")
img, _, _ := image.Decode(f)
analyzer := smartcrop.NewAnalyzer()
topCrop, _ := analyzer.FindBestCrop(img, 250, 250)
fmt.Printf("Top crop: %+v\n", topCrop)
}
Also see the test cases in crop_test.go for further working examples.
You can find a bunch of test images for the algorithm here.
API docs can be found here.
Join us on IRC: irc.freenode.net/#smartcrop