All Projects → muesli → Smartcrop

muesli / Smartcrop

Licence: mit
smartcrop finds good image crops for arbitrary crop sizes

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Smartcrop

Lens Regex Pcre
Text lenses using PCRE regexes
Stars: ✭ 116 (-92.6%)
Mutual labels:  hacktoberfest
Reactstrap
Simple React Bootstrap 5 components
Stars: ✭ 10,207 (+551.37%)
Mutual labels:  hacktoberfest
Sentry Php
The official PHP SDK for Sentry (sentry.io)
Stars: ✭ 1,591 (+1.53%)
Mutual labels:  hacktoberfest
Mongoframework
An "Entity Framework"-like interface for MongoDB
Stars: ✭ 116 (-92.6%)
Mutual labels:  hacktoberfest
Dbatools
🚀 SQL Server automation and instance migrations have never been safer, faster or freer
Stars: ✭ 1,742 (+11.17%)
Mutual labels:  hacktoberfest
Skeletonview
☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting
Stars: ✭ 10,804 (+589.47%)
Mutual labels:  hacktoberfest
Maria Quiteria
Backend para coleta e disponibilização dos dados 📜
Stars: ✭ 115 (-92.66%)
Mutual labels:  hacktoberfest
Cxbx Reloaded
Xbox (Original) Emulator
Stars: ✭ 1,746 (+11.42%)
Mutual labels:  hacktoberfest
Cyclejs
A functional and reactive JavaScript framework for predictable code
Stars: ✭ 9,996 (+537.91%)
Mutual labels:  hacktoberfest
Quinn
Async-friendly QUIC implementation in Rust
Stars: ✭ 1,859 (+18.63%)
Mutual labels:  hacktoberfest
Component Docs
📝 Simple documentation for your React components
Stars: ✭ 116 (-92.6%)
Mutual labels:  hacktoberfest
Python Gitlab
Python wrapper for the GitLab API
Stars: ✭ 1,679 (+7.15%)
Mutual labels:  hacktoberfest
Fhir
The IBM® FHIR® Server and related projects
Stars: ✭ 117 (-92.53%)
Mutual labels:  hacktoberfest
Singapore Tech Internships
🏢 (Updated Dec 2020) Singapore Tech Internships!
Stars: ✭ 116 (-92.6%)
Mutual labels:  hacktoberfest
Duckstation
Fast PlayStation 1 emulator for x86-64/AArch32/AArch64
Stars: ✭ 2,888 (+84.3%)
Mutual labels:  hacktoberfest
Docat
Host your docs. Simple. Versioned. Fancy.
Stars: ✭ 115 (-92.66%)
Mutual labels:  hacktoberfest
Beets
music library manager and MusicBrainz tagger
Stars: ✭ 10,522 (+571.47%)
Mutual labels:  hacktoberfest
Kubefed
Kubernetes Cluster Federation
Stars: ✭ 1,955 (+24.76%)
Mutual labels:  hacktoberfest
Zoid
Cross domain components
Stars: ✭ 1,672 (+6.7%)
Mutual labels:  hacktoberfest
Perfil Politico
A platform for profiling public figures in Brazilian politics
Stars: ✭ 117 (-92.53%)
Mutual labels:  hacktoberfest

smartcrop

Build Status Coverage Status Go ReportCard GoDoc

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].