https://github.com/muesli/smartcrop
smartcrop finds good image crops for arbitrary crop sizes
https://github.com/muesli/smartcrop
hacktoberfest
Last synced: 10 months ago
JSON representation
smartcrop finds good image crops for arbitrary crop sizes
- Host: GitHub
- URL: https://github.com/muesli/smartcrop
- Owner: muesli
- License: mit
- Created: 2014-04-07T22:40:03.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2023-07-06T12:16:16.000Z (over 2 years ago)
- Last Synced: 2025-04-10T18:31:28.525Z (11 months ago)
- Topics: hacktoberfest
- Language: Go
- Homepage:
- Size: 21.1 MB
- Stars: 1,830
- Watchers: 33
- Forks: 112
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- fucking-awesome-go - smartcrop - Finds good crops for arbitrary images and crop sizes. (Images / Search and Analytic Databases)
- go-awesome - smartcrop - 智能裁剪图片 (开源类库 / 图形处理)
- awesome-go - smartcrop - Finds good crops for arbitrary images and crop sizes. Stars:`1.8K`. (Images / Search and Analytic Databases)
- go-awesome - smartcrop - Smart cropping of images (Open source library / Graphics Processing)
- awesome-go - smartcrop - smartcrop finds good image crops for arbitrary crop sizes - ★ 1180 (Images)
- awesome-go-with-stars - smartcrop - 03-16 | (Images / Search and Analytic Databases)
- awesome-go-info - smartcrop
- awesome-go - smartcrop - Finds good crops for arbitrary images and crop sizes. - :arrow_down:15 - :star:304 (Images / Advanced Console UIs)
- awesome-go-extra - smartcrop - 04-07T22:40:03Z|2022-04-11T14:16:31Z| (Images / Advanced Console UIs)
- awesome-go - smartcrop - Finds good crops for arbitrary images and crop sizes. (Images / Search and Analytic Databases)
- awesome-go - smartcrop - Finds good crops for arbitrary images and crop sizes. (Images / Search and Analytic Databases)
- awesome-go-cn - smartcrop
- awesome-go - smartcrop - Finds good crops for arbitrary images and crop sizes. (Images / Search and Analytic Databases)
- awesome-go - smartcrop - Finds good crops for arbitrary images and crop sizes. (Images / Search and Analytic Databases)
- awesome-go-cn - smartcrop - 为任意图片进行剪裁的工具 (Images 图像处理 / SQL 查询语句构建库)
- awesome-go-cn - smartcrop
- awesome-go-cn - smartcrop
- awesome-go - smartcrop - Finds good crops for arbitrary images and crop sizes. (Images / Advanced Console UIs)
- go-awesome-with-star-updatetime - smartcrop - Finds good crops for arbitrary images and crop sizes. (Images / Advanced Console UIs)
- awesome-go-zh - smartcrop
- awesome-Char - smartcrop - Finds good crops for arbitrary images and crop sizes. (Images / Advanced Console UIs)
- awesome-go - smartcrop - Finds good crops for arbitrary images and crop sizes. (Images / Search and Analytic Databases)
- awesome-go - smartcrop - | - | - | (Images / Advanced Console UIs)
- awesome-go - smartcrop - Finds good crops for arbitrary images and crop sizes. (<span id="图片-images">图片 Images</span> / <span id="高级控制台用户界面-advanced-console-uis">高级控制台用户界面 Advanced Console UIs</span>)
- awesome-go-processed - smartcrop - Finds good crops for arbitrary images and crop sizes.| (Images / Advanced Console UIs)
- fucking-awesome-go - :octocat: smartcrop - Finds good crops for arbitrary images and crop sizes :star: 291 :fork_and_knife: 26 (Images / Advanced Console UIs)
- awesome-go - smartcrop - Finds good crops for arbitrary images and crop sizes. (Images / Advanced Console UIs)
- awesome-go-plus - smartcrop - Finds good crops for arbitrary images and crop sizes.  (Images / Search and Analytic Databases)
- awesome-go - smartcrop - Finds good crops for arbitrary images and crop sizes. (Images / Search and Analytic Databases)
README
smartcrop
=========
[](https://github.com/muesli/smartcrop/releases)
[](https://github.com/muesli/smartcrop/actions)
[](https://coveralls.io/github/muesli/smartcrop?branch=master)
[](https://goreportcard.com/report/muesli/smartcrop)
[](https://godoc.org/github.com/muesli/smartcrop)
smartcrop finds good image crops for arbitrary sizes. It is a pure Go implementation, based on Jonas Wagner's [smartcrop.js](https://github.com/jwagner/smartcrop.js)

Image: [https://www.flickr.com/photos/usfwspacific/8182486789](https://www.flickr.com/photos/usfwspacific/8182486789) by Washington Dept of Fish and Wildlife, originally licensed under [CC-BY-2.0](https://creativecommons.org/licenses/by/2.0/) when the image was imported back in September 2014

Image: [https://www.flickr.com/photos/endogamia/5682480447](https://www.flickr.com/photos/endogamia/5682480447) by Leon F. Cabeiro (N. Feans), licensed under [CC-BY-2.0](https://creativecommons.org/licenses/by/2.0/)
## Installation
Make sure you have a working Go environment (Go 1.12 or higher is required).
See the [install instructions](https://golang.org/doc/install.html).
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
```go
package main
import (
"fmt"
"image"
_ "image/png"
"os"
"github.com/muesli/smartcrop"
"github.com/muesli/smartcrop/nfnt"
)
func main() {
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 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 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
Example:
smartcrop -input examples/gopher.jpg -output gopher_cropped.jpg -width 300 -height 150
## Sample Data
You can find a bunch of test images for the algorithm [here](https://github.com/muesli/smartcrop-samples).
## Feedback
Got some feedback or suggestions? Please open an issue or drop me a note!
* [Twitter](https://twitter.com/mueslix)
* [The Fediverse](https://mastodon.social/@fribbledom)