smartcrop

smartcrop finds good image crops for arbitrary crop sizes

  • 所有者: muesli/smartcrop
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

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 by Washington Dept of Fish and Wildlife, originally licensed under CC-BY-2.0 when the image was imported back in September 2014

Example
Image: https://www.flickr.com/photos/endogamia/5682480447 by Leon F. Cabeiro (N. Feans), licensed under CC-BY-2.0

Installation

Make sure you have a working Go environment (Go 1.9 or higher is required).
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"
	"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

cd $GOPATH/src/github.com/muesli/smartcrop  
go install ./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.

Development

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

GoDoc
Build Status
Coverage Status
Go ReportCard

主要指標

概覽
名稱與所有者muesli/smartcrop
主編程語言Go
編程語言Go (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2014-04-07 22:40:03
推送於2023-07-06 12:16:16
最后一次提交2023-03-16 12:59:11
發布數4
最新版本名稱v0.3.0 (發布於 )
第一版名稱0.1 (發布於 )
用户参与
星數1.8k
關注者數33
派生數113
提交數169
已啟用問題?
問題數20
打開的問題數6
拉請求數25
打開的拉請求數3
關閉的拉請求數7
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?