Files
mostlymatter/vendor/github.com/muesli/smartcrop
Harrison Healey ba5566d1a0 MM-10417 Add local image proxy and enable by default (#9967)
* MM-10417 Add local image proxy and enable by default

* Remove unused function

* Add dependencies for willnorris/imageproxy

* Fixed compilation errors

* Lock to the master version of willnorris/imageproxy

* Fix atmos/camo proxy when no SiteURL is specified

* Re-add default values for deprecated settings

* Fix unit tests added by merge

* Pass imageproxy to App struct

* Remove unneeded locking when creating the image proxy

* Remove empty test file
2019-01-24 16:11:32 -04:00
..

smartcrop

smartcrop finds good image crops for arbitrary sizes. It is a pure Go implementation, based on Jonas Wagner's smartcrop.js

Example Image: https://www.flickr.com/photos/usfwspacific/8182486789 CC BY U.S. Fish & Wildlife

Example Image: https://www.flickr.com/photos/endogamia/5682480447 by N. Feans

Installation

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

Example

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)

        // The crop will have the requested aspect ratio, but you need to copy/scale it yourself
        fmt.Printf("Top crop: %+v\n", topCrop)

        type SubImager interface {
                SubImage(r image.Rectangle) image.Image
        }
        croppedimg := img.(SubImager).SubImage(topCrop)
        ...
}

Also see the test cases in crop_test.go for further working examples.

Sample Data

You can find a bunch of test images for the algorithm here.

Development

API docs can be found here.

Join us on IRC: irc.freenode.net/#smartcrop

Build Status Coverage Status Go ReportCard