https://github.com/thearchitector/smartclip
A contextually-aware paperclip processor that crops and scales your images to maximize aesthetic quality
https://github.com/thearchitector/smartclip
algorithm image image-processing paperclip paperclip-processor
Last synced: 5 days ago
JSON representation
A contextually-aware paperclip processor that crops and scales your images to maximize aesthetic quality
- Host: GitHub
- URL: https://github.com/thearchitector/smartclip
- Owner: thearchitector
- License: bsd-2-clause
- Created: 2017-08-20T16:31:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-30T15:39:06.000Z (over 7 years ago)
- Last Synced: 2025-03-03T10:15:21.806Z (9 months ago)
- Topics: algorithm, image, image-processing, paperclip, paperclip-processor
- Language: Ruby
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Smartclip
Smartclip is a contextually-aware paperclip processor that crops and scales your images to maximize aesthetic quality.
> While initially written as a passion project for [The Glass Files](https://www.theglassfiles.com/), I've abstracted away all the hardcoded specifics so it should work generically. Images smaller than the desired thumbnail size are automatically padded with a border rather than being enlarged.
## The Algorithm
The algorithm is fairly simple and is an adjusted a port of [smartcrop.js](https://github.com/jwagner/smartcrop.js) by Jonas Wagner:
* Find edges
* Find regions with a color like skin
* Find regions high in saturation
* Generate a set of thumbnail candidates
* Rank candidates using an importance function to focus the detail in the center and avoid it in the edges.
* The highest ranking candidate is selected and is processed by Paperclip
## Example
The process is super simple, and is basically identical to using any other Paperclip processor:
```ruby
# Your path might be different, so adjust as necessary
require "#{Rails.root}/lib/paperclip_processors/smartclip"
...
styles: { thumb: { resize_width: 150, resize_height: 150, processors: [:smartclip] } }
```
## Future Plans
* Wrap within gem for easy installation
* Optimize pixel iteration to reduce number of loops. Can it be done without screwing with saliency patterns?
* Port and integrate face detection algorithm
* Completely rewrite to favor deep neural networks? Benefits from more complicated criteria, and can be trained from professional data rather than guesses
* _Extract optimzation logic, along with what I've learned, to create separate image optmization processor?_
## Found Bugs?
If you found a bug, submit an issue. If you have some optimization insight, submit a Pull Request.