内容感知图像裁剪:smartcrop.js
jopen
9年前
Smartcrop.js实现了一种算法来进行更好的进行截图。
Image: https://www.flickr.com/photos/endogamia/5682480447/ by N. Feans
示例
- Test Suite, contains over 100 images, heavy
- Test Bed, allows you to upload your own images
- Photo transitions, automatically creats ken burns transitions for a slide show.
算法概览
Smartcrop.js works using fairly dumb image processing. In short:
- Find edges using laplace
- Find regions with a color like skin
- Find regions high in saturation
- Generate a set of candidate crops using a sliding window
- Rank them using a importance function to focus the detail in the center and avoid it in the edges.
- Output the candidate crop with the highest rank
Simple Example
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 smartcroporbower install smartcropor 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