smartcrop

package module
Version: v0.0.0-...-7a9cbb9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2015 License: MIT Imports: 14 Imported by: 1

README

smartcrop.go

smartcrop implementation in Go.

This is a fork of github.com/muesli/smartcrop with dependency on opencv removed, API simplifications and speed optimizatons.

smartcrop finds good crops for arbitrary images and crop sizes, based on Jonas Wagner's smartcrop.js

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

See https://godoc.org/github.com/artyom/smartcrop for API and usage example.

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

func Crop

func Crop(img image.Image, width, height int) (image.Rectangle, error)

SmartCrop applies the smartcrop algorithms on the the given image and returns the top crop or an error if something went wrong.

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL