Skip to content

JavaScriptCodes/smartcrop.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smartcrop.js

WARNING: This is a work in progress. Neither the API nor the algorithm are finished. (Automated) verification, testing and benchmarking are yet to be done.

Smartcrop.js implements an algorithm to find good crops for images.

Example Image: https://www.flickr.com/photos/endogamia/5682480447/ by N. Feans

It does this using fairly dumb image processing. In short:

  1. Find edges using laplace
  2. Find regions with a color like skin
  3. Find regions high in saturation
  4. Generate a set of candidate crops
  5. Rank them using a importance function to focus the detail in the center and avoid it in the edges.
  6. Output the candidate crop with the highest rank

Demos

  • Test Suite containing over 100 images, heavy
  • Test Bed allows you to upload your own images

Simple Example

var result = SmartCrop.crop(image, {width: 100, height: 100}, function(result){console.log(result);});
// {topCrop: {x: 300, y: 200, height: 200, width: 200}}

Download/ Installation

npm install smartcrop or bower install smartcrop or just download smartcrop.js from the git repo.

CLI / Node.js

The smartcrop-cli offers command line interface to smartcrop.js. It is based on node.js and node-canvas. You can also view it as an example on how to use smartcrop.js from a node.js app.

Module Formats

Supported:

  • common js
  • amd
  • global export / window

Supported Browsers

See caniuse.com/canvas

API

The API is not yet finalized. Look at the code and expect changes.

About

Content aware image cropping

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 95.5%
  • HTML 4.5%