Documentation ¶
Overview ¶
Package smartcrop is a pure-Go implementation of content aware image cropping based on Jonas Wagner's smartcrop.js https://github.com/jwagner/smartcrop.js
Example ¶
package main import ( "fmt" "image" "log" "os" "github.com/artyom/smartcrop" ) func main() { fi, err := os.Open("./samples/gopher.jpg") if err != nil { log.Fatal(err) } defer fi.Close() img, _, err := image.Decode(fi) if err != nil { log.Fatal(err) } topCrop, err := smartcrop.Crop(img, 250, 250) if err != nil { log.Fatal(err) } fmt.Println("best crop is", topCrop) type subImager interface { SubImage(image.Rectangle) image.Image } if si, ok := img.(subImager); ok { cr := si.SubImage(topCrop) fmt.Printf("cropped image dimensions are %d x %d", cr.Bounds().Dx(), cr.Bounds().Dy()) } }
Output: best crop is (59,0)-(486,427) cropped image dimensions are 427 x 427
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.